home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / emacs-complete / fsf / emacs / lisp / gnus-uu.el < prev    next >
Lisp/Scheme  |  1994-06-20  |  111KB  |  3,058 lines

  1. ;;; gnus-uu.el --- extract, view or save (uu)encoded files from gnus
  2.  
  3. ;; Copyright (C) 1985, 1986, 1987, 1993, 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Lars Ingebrigtsen <larsi@ifi.uio.no>
  6. ;; Created: 2 Oct 1993
  7. ;; Version: v2.8
  8. ;; Last Modified: 1994/06/01
  9. ;; Keyword: news
  10.  
  11. ;; This file is part of GNU Emacs.
  12.  
  13. ;; GNU Emacs is free software; you can redistribute it and/or modify
  14. ;; it under the terms of the GNU General Public License as published by
  15. ;; the Free Software Foundation; either version 2, or (at your option)
  16. ;; any later version.
  17.  
  18. ;; GNU Emacs is distributed in the hope that it will be useful,
  19. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. ;; GNU General Public License for more details.
  22.  
  23. ;; You should have received a copy of the GNU General Public License
  24. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  25. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  26.  
  27. ;;; Commentary:
  28.  
  29. ;; All gnus-uu commands start with `C-c C-v'.
  30. ;;
  31. ;; Short user manual for this package:
  32. ;;
  33. ;; Type `C-c C-v C-v' to decode and view all articles of the current
  34. ;; series. The defaults should be reasonable for most systems.
  35. ;;
  36. ;; Type `C-c C-v C-i' to toggle interactive mode. When using
  37. ;; interactive mode, gnus-uu will which display a buffer that will let
  38. ;; you see the suggested commands to be executed.
  39. ;;
  40. ;; To post an uuencoded file, type `C-c C-v p', which will enter you
  41. ;; into a buffer analogous to the one you will get when typing `a'. Do
  42. ;; an `M-x describe-mode' in this buffer to get a description of what
  43. ;; this buffer lets you do.
  44. ;;
  45. ;; Read the documentation of the `gnus-uu' dummy function for a more
  46. ;; complete description of what this package does and how you can
  47. ;; customize it to fit your needs.
  48. ;; 
  49. ;;
  50. ;;
  51. ;; History
  52. ;;
  53. ;; v1.0: First version released Oct 2 1992.
  54. ;;
  55. ;; v1.1: Changed `C-c C-r' to `C-c C-e' and `C-c C-p' to `C-c C-k'.
  56. ;; Changed (setq gnus-exit-group-hook) to (add-hook).  Removed
  57. ;; checking for "Re:" for finding parts.
  58. ;;
  59. ;; v2.2: Fixed handling of currupted archives. Changed uudecoding to
  60. ;; an asynchronous process to avoid loading tons of data into emacs
  61. ;; buffers. No longer reads articles emacs already have aboard.  Fixed
  62. ;; a firmer support for shar files. Made regexp searches for files
  63. ;; more convenient. Added `C-c C-l' for editing uucode begin
  64. ;; lines. Added multi-system decoder entry point. Added interactive
  65. ;; view mode. Added function for decoding and saving all uuencoded
  66. ;; articles in the current newsgroup.
  67. ;;
  68. ;; v2.3: After suggestions I have changed all the gnus-uu key bindings
  69. ;; to avoid hogging all the user keys (C-c LETTER). Also added
  70. ;; (provide) and fixed some saving stuff. First posted version to
  71. ;; gnu.emacs.sources.
  72. ;;
  73. ;; v2.4: Fixed some more in the save-all category. Automatic fixing of
  74. ;; uucode "begin" lines: names on the form of "dir/file" are
  75. ;; translated into "dir-file". Added a function for fixing stripped
  76. ;; uucode articles. Added binhex save.
  77. ;;
  78. ;; v2.5: First version copyrighted by FSF. Changed lots of
  79. ;; documentation strings.
  80. ;;
  81. ;; v2.5.1: Added uuencode/posting code to post binary files. 
  82. ;;
  83. ;; v2.6: Thread support. gnus-uu is now able to decode uuencoded files
  84. ;; posted in threads. gnus-uu can also post in threads. I don't know
  85. ;; if this ability is of much use - I've never seen anyone post
  86. ;; uuencoded files in threads.
  87. ;;
  88. ;; v2.7: gnus-uu is now able to decode (and view/save) multiple
  89. ;; encoded files in one big gulp. Also added pseudo-mime support
  90. ;; (users can use metamail to view files), posting uuencoded/mime
  91. ;; files and various other bits and pieces.
  92. ;;
  93. ;; v2.7.1: New functions for decoding/saving threads bound to `C-c
  94. ;; C-v C-j'. Handy to save entire threads, not very useful for
  95. ;; decoding, as nobody posts encoded files in threads...
  96. ;;
  97. ;; v2.7.2: New functions for digesting and forwarding articles added
  98. ;; on the suggestion of Per Abrahamsen. Also added a function for
  99. ;; marking threads. 
  100. ;;
  101. ;; v2.8: Fixed saving original files in interactive mode. Fixed ask
  102. ;; before/save after view. Fixed setting up interactive buffers. Added
  103. ;; scanning and rescanning from interactive mode. Added the
  104. ;; `gnus-uu-ignore-file-by-name' and `...-by-type' variables to allow
  105. ;; users to sift files they don't want to view. At the suggestion of
  106. ;; boris@cs.rochester.edu, `C-c C-v C-h' has been undefined to allow
  107. ;; users to view list of binding beginning with `C-c C-v'. Fixed
  108. ;; viewing with `gnus-uu-asynchronous' set. The
  109. ;; "decode-and-save/view-all-articles" functions now accepts the
  110. ;; numeric prefix to delimit the maximum number of files to be
  111. ;; decoded.
  112.  
  113. ;;; Code: 
  114.  
  115. (require 'gnus)
  116. (require 'gnuspost)
  117.  
  118. ;; Binding of keys to the gnus-uu functions.
  119.  
  120. (defvar gnus-uu-ctl-map nil)
  121. (define-prefix-command 'gnus-uu-ctl-map)
  122. (define-key gnus-summary-mode-map "\C-c\C-v" gnus-uu-ctl-map)
  123.  
  124. (define-key gnus-uu-ctl-map "\C-v" 'gnus-uu-decode-and-view)
  125. (define-key gnus-uu-ctl-map "v" 'gnus-uu-decode-and-save)
  126. (define-key gnus-uu-ctl-map "\C-s" 'gnus-uu-shar-and-view)
  127. (define-key gnus-uu-ctl-map "s" 'gnus-uu-shar-and-save)
  128. (define-key gnus-uu-ctl-map "\C-m" 'gnus-uu-multi-decode-and-view)
  129. (define-key gnus-uu-ctl-map "m" 'gnus-uu-multi-decode-and-save)
  130.  
  131. (define-key gnus-uu-ctl-map "\C-b" 'gnus-uu-decode-and-show-in-buffer)
  132.  
  133. (define-key gnus-summary-mode-map "#" 'gnus-uu-mark-article)
  134. (define-key gnus-summary-mode-map "\M-#" 'gnus-uu-unmark-article)
  135. (define-key gnus-uu-ctl-map "\C-u" 'gnus-uu-unmark-all-articles)
  136. (define-key gnus-uu-ctl-map "\C-r" 'gnus-uu-mark-by-regexp)
  137. (define-key gnus-uu-ctl-map "r" 'gnus-uu-mark-by-regexp)
  138. (define-key gnus-uu-ctl-map "t" 'gnus-uu-mark-thread)
  139.  
  140. (define-key gnus-uu-ctl-map "\M-\C-v" 'gnus-uu-marked-decode-and-view)
  141. (define-key gnus-uu-ctl-map "\M-v" 'gnus-uu-marked-decode-and-save)
  142. (define-key gnus-uu-ctl-map "\M-\C-s" 'gnus-uu-marked-shar-and-view)
  143. (define-key gnus-uu-ctl-map "\M-s" 'gnus-uu-marked-shar-and-save)
  144. (define-key gnus-uu-ctl-map "\M-\C-m" 'gnus-uu-marked-multi-decode-and-view)
  145. (define-key gnus-uu-ctl-map "\M-m" 'gnus-uu-marked-multi-decode-and-save)
  146.  
  147. (define-key gnus-uu-ctl-map "f" 'gnus-uu-digest-and-forward)
  148. (define-key gnus-uu-ctl-map "\M-f" 'gnus-uu-marked-digest-and-forward)
  149.  
  150. (define-key gnus-uu-ctl-map "\C-i" 'gnus-uu-toggle-interactive-view)
  151. (define-key gnus-uu-ctl-map "\C-t" 'gnus-uu-toggle-any-variable)
  152.  
  153. (define-key gnus-uu-ctl-map "\C-l" 'gnus-uu-edit-begin-line)
  154.  
  155. (define-key gnus-uu-ctl-map "a" 'gnus-uu-decode-and-save-all-unread-articles)
  156. (define-key gnus-uu-ctl-map "w" 'gnus-uu-decode-and-save-all-articles)
  157. (define-key gnus-uu-ctl-map "\C-a" 'gnus-uu-decode-and-view-all-unread-articles)
  158. (define-key gnus-uu-ctl-map "\C-w" 'gnus-uu-decode-and-view-all-articles)
  159.  
  160. (define-key gnus-uu-ctl-map "\C-j" 'gnus-uu-threaded-multi-decode-and-view)
  161. (define-key gnus-uu-ctl-map "j" 'gnus-uu-threaded-multi-decode-and-save)
  162.  
  163. (define-key gnus-uu-ctl-map "p" 'gnus-uu-post-news)
  164.  
  165. ;; Dummy function gnus-uu
  166.  
  167. (defun gnus-uu ()
  168.   "gnus-uu is a package for uudecoding and viewing articles.
  169.  
  170.  
  171. Keymap overview:
  172.  
  173. By default, all gnus-uu keystrokes begin with `C-c C-v'. 
  174.  
  175. There four decoding commands categories:
  176. All commands for viewing are `C-c C-v C-LETTER'.
  177. All commands for saving are `C-c C-v LETTER'.
  178. All commands for marked viewing are `C-c C-v C-M-LETTER'.
  179. All commands for marked saving are `C-c C-v M-LETTER'.
  180.  
  181. \\<gnus-summary-mode-map>\\[gnus-uu-decode-and-view]\tDecode and view articles
  182. \\[gnus-uu-decode-and-save]\tDecode and save articles
  183. \\[gnus-uu-shar-and-view]\tUnshar and view articles
  184. \\[gnus-uu-shar-and-save]\tUnshar and save articles
  185. \\[gnus-uu-multi-decode-and-view]\tChoose a decoding method, decode and view articles
  186. \\[gnus-uu-multi-decode-and-save]\tChoose a decoding method, decode and save articles
  187.  
  188. \\[gnus-uu-threaded-multi-decode-and-view]\tDecode a thread and view
  189. \\[gnus-uu-threaded-multi-decode-and-save]\tDecode a thread and save
  190.  
  191. \\[gnus-uu-decode-and-show-in-buffer]\tDecode the current article and view the result in a buffer
  192. \\[gnus-uu-edit-begin-line]\tEdit the 'begin' line of an uuencoded article
  193.  
  194. \\[gnus-uu-decode-and-save-all-unread-articles]\tDecode and save all unread articles
  195. \\[gnus-uu-decode-and-save-all-articles]\tDecode and save all articles
  196. \\[gnus-uu-decode-and-view-all-unread-articles]\tDecode and view all unread articles
  197. \\[gnus-uu-decode-and-view-all-articles]\tDecode and view all articles
  198.  
  199. \\[gnus-uu-digest-and-forward]\tDigest and forward a series of articles
  200. \\[gnus-uu-marked-digest-and-forward]\tDigest and forward all marked articles
  201.  
  202. \\[gnus-uu-mark-article]\tMark the current article for decoding
  203. \\[gnus-uu-unmark-article]\tUnmark the current article
  204. \\[gnus-uu-unmark-all-articles]\tUnmark all articles
  205. \\[gnus-uu-mark-by-regexp]\tMark articles for decoding by regexp
  206. \\[gnus-uu-mark-thread]\tMark articles in this thread
  207. \\[gnus-uu-marked-decode-and-view]\tDecode and view marked articles
  208. \\[gnus-uu-marked-decode-and-save]\tDecode and save marked articles
  209. \\[gnus-uu-marked-shar-and-view]\tUnshar and view marked articles
  210. \\[gnus-uu-marked-shar-and-save]\tUnshar and save marked articles
  211. \\[gnus-uu-marked-multi-decode-and-view]\tChoose decoding method, decode and view marked articles
  212. \\[gnus-uu-marked-multi-decode-and-save]\tChoose decoding method, decode and save marked articles
  213.  
  214. \\[gnus-uu-toggle-asynchronous]\tToggle asynchronous viewing mode
  215. \\[gnus-uu-toggle-query]\tToggle whether to ask before viewing a file
  216. \\[gnus-uu-toggle-always-ask]\tToggle whether to ask to save a file after viewing
  217. \\[gnus-uu-toggle-kill-carriage-return]\tToggle whether to strip trailing carriage returns
  218. \\[gnus-uu-toggle-interactive-view]\tToggle whether to use interactive viewing mode
  219. \\[gnus-uu-toggle-correct-stripped-articles]\tToggle whether to 'correct' articles
  220. \\[gnus-uu-toggle-view-with-metamail]\tToggle whether to use metamail for viewing 
  221. \\[gnus-uu-toggle-any-variable]\tToggle any of the things above
  222.  
  223. \\[gnus-uu-post-news]\tPost an uuencoded article
  224.  
  225. Function description:
  226.  
  227. `gnus-uu-decode-and-view' will try to find all articles in the same
  228. series, uudecode them and view the resulting file(s).
  229.  
  230. gnus-uu guesses what articles are in the series according to the
  231. following simplish rule: The subjects must be (nearly) identical,
  232. except for the last two numbers of the line. (Spaces are largely
  233. ignored, however.)
  234.  
  235. For example: If you choose a subject called 
  236.   \"cat.gif (2/3)\"
  237. gnus-uu will find all the articles that matches
  238.   \"^cat.gif ([0-9]+/[0-9]+).*$\".  
  239.  
  240. Subjects that are nonstandard, like 
  241.   \"cat.gif (2/3) Part 6 of a series\", 
  242. will not be properly recognized by any of the automatic viewing
  243. commands, and you have to mark the articles manually with '#'.
  244.  
  245. `gnus-uu-decode-and-save' will do the same as
  246. `gnus-uu-decode-and-view', except that it will not display the
  247. resulting file, but save it instead.
  248.  
  249. `gnus-uu-shar-and-view' and `gnus-uu-shar-and-save' are the \"shar\"
  250. equivalents to the uudecode functions. Instead of feeding the articles
  251. to uudecode, they are run through /bin/sh. Most shar files can be
  252. viewed and/or saved with the normal uudecode commands, which is much
  253. safer, as no foreign code is run.
  254.  
  255. Instead of having windows popping up automatically, it can be handy to
  256. view files interactivly, especially when viewing archives. Use
  257. `gnus-uu-toggle-interactive-mode' to toggle interactive mode.
  258.  
  259. `gnus-uu-mark-article' marks an article for later
  260. decoding/unsharing/saving/viewing. The files will be decoded in the
  261. sequence they were marked. To decode the files after you've marked the
  262. articles you are interested in, type the corresponding key strokes as
  263. the normal decoding commands, but put a `M-' in the last
  264. keystroke. For instance, to perform a standard uudecode and view, you
  265. would type `C-c C-v C-v'. To perform a marked uudecode and view, say
  266. `C-v C-v M-C-v'. All the other view and save commands are handled the
  267. same way; marked uudecode and save is then `C-c C-v M-v'.
  268.  
  269. `gnus-uu-unmark-article' will remove the mark from a previosly marked
  270. article.
  271.  
  272. `gnus-uu-unmark-all-articles' will remove the mark from all marked
  273. articles.
  274.  
  275. `gnus-uu-mark-by-regexp' will prompt for a regular expression and mark
  276. all articles matching that regular expression.
  277.  
  278. `gnus-uu-mark-thread' will mark all articles downward in the current
  279. thread.
  280.  
  281. There's an additional way to reach the decoding functions to make
  282. future expansions easier: `gnus-uu-multi-decode-and-view' and the
  283. corresponding save, marked view and marked save functions. You will be
  284. prompted for a decoding method, like uudecode, shar, binhex or plain
  285. save. Note that methods like binhex and save doesn't have view modes;
  286. even if you issue a view command (`C-c C-v C-m' and \"binhex\"),
  287. gnus-uu will just save the resulting binhex file.
  288.  
  289. `gnus-uu-decode-and-show-in-buffer' will decode the current article
  290. and display the results in an emacs buffer. This might be useful if
  291. there's jsut some text in the current article that has been uuencoded
  292. by some perverse poster.
  293.  
  294. `gnus-uu-decode-and-save-all-articles' looks at all the articles in
  295. the current newsgroup and tries to uudecode everything it can
  296. find. The user will be prompted for a directory where the resulting
  297. files (if any) will be
  298. saved. `gnus-uu-decode-and-save-unread-articles' does only checks
  299. unread articles. 
  300.  
  301. `gnus-uu-decode-and-view-all-articles' does the same as the function
  302. above, only viewing files instead of saving them. 
  303.  
  304. `gnus-uu-edit-begin-line' lets you edit the begin line of an uuencoded
  305. file in the current article. Useful to change a corrupted begin line.
  306.  
  307.  
  308. When using the view commands, `gnus-uu-decode-and-view' for instance,
  309. gnus-uu will (normally, see below) try to view the file according to
  310. the rules given in `gnus-uu-default-view-rules' and
  311. `gnus-uu-user-view-rules'. If it recognizes the file, it will display
  312. it immediately. If the file is some sort of archive, gnus-uu will
  313. attempt to unpack the archive and see if any of the files in the
  314. archive can be viewed. For instance, if you have a gzipped tar file
  315. \"pics.tar.gz\" containing the files \"pic1.jpg\" and \"pic2.gif\",
  316. gnus-uu will uncompress and detar the main file, and then view the two
  317. pictures. This unpacking process is recursive, so if the archive
  318. contains archives of archives, it'll all be unpacked.
  319.  
  320. If the view command doesn't recognise the file type, or can't view it
  321. because you don't have the viewer, or can't view *any* of the files in
  322. the archive, the user will be asked if she wishes to have the file
  323. saved somewhere. Note that if the decoded file is an archive, and
  324. gnus-uu manages to view some of the files in the archive, it won't
  325. tell the user that there were some files that were unviewable. Try
  326. interactive view for a different approach.
  327.  
  328.  
  329. Note that gnus-uu adds a function to `gnus-exit-group-hook' to clear
  330. the list of marked articles and check for any generated files that
  331. might have escaped deletion if the user typed `C-g' during viewing.
  332.  
  333.  
  334. `gnus-uu-toggle-asynchronous' toggles the `gnus-uu-asynchronous'
  335. variable.
  336.  
  337. `gnus-uu-toggle-query' toggles the `gnus-uu-ask-before-view'
  338. variable.
  339.  
  340. `gnus-uu-toggle-always-ask' toggles the `gnus-uu-view-and-save'
  341. variable.
  342.  
  343. `gnus-uu-toggle-kill-carriage-return' toggles the
  344. `gnus-uu-kill-carriage-return' variable.
  345.  
  346. `gnus-uu-toggle-interactive-view' toggles interactive mode. If it is
  347. turned on, gnus-uu won't view files immediately, but will give you a
  348. buffer with the default commands and files and let you edit the
  349. commands and execute them at leisure.
  350.  
  351. `gnus-uu-toggle-correct-stripped-articles' toggles whether to check
  352. and correct uuencoded articles that may have had trailing spaces
  353. stripped by mailers.
  354.  
  355. `gnus-uu-toggle-view-with-metamail' toggles whether to skip the
  356. gnus-uu viewing methods and just guess at an content-type based on the
  357. file name suffix and feed it to metamail.
  358.  
  359. `gnus-uu-toggle-any-variable' is an interface to the toggle commands
  360. listed above.
  361.  
  362.  
  363. Customization
  364.  
  365.    Rule Variables
  366.  
  367.    gnus-uu uses \"rule\" variables to decide how to view a file. All
  368.    these variables are of the form
  369.   
  370.       (list '(regexp1 command2)
  371.             '(regexp2 command2)
  372.             ...)
  373.  
  374.    `gnus-uu-user-view-rules'
  375.      This variable is consulted first when viewing files. If you wish
  376.      to use, for instance, sox to convert an .au sound file, you could
  377.      say something like:
  378.  
  379.        (setq gnus-uu-user-view-rules
  380.          (list '(\"\\\\.au$\" \"sox %s -t .aiff > /dev/audio\")))
  381.  
  382.    `gnus-uu-user-view-rules-end'
  383.      This variable is consulted if gnus-uu couldn't make any matches
  384.      from the user and default view rules.
  385.  
  386.    `gnus-uu-user-interactive-view-rules'
  387.      This is the variable used instead of `gnus-uu-user-view-rules'
  388.      when in interactive mode.
  389.  
  390.    `gnus-uu-user-interactive-view-rules-end'
  391.      This variable is used instead of `gnus-uu-user-view-rules-end'
  392.      when in interactive mode.
  393.  
  394.    `gnus-uu-user-archive-rules`
  395.      This variable can be used to say what comamnds should be used to
  396.      unpack archives.
  397.  
  398.    
  399.    Other Variables
  400.  
  401.    `gnus-uu-ignore-files-by-name'
  402.      Files with name matching this regular expression won't be viewed.
  403.  
  404.    `gnus-uu-ignore-files-by-type'
  405.      Files with a MIME type matching this variable won't be viewed.
  406.      Note that gnus-uu tries to guess what type the file is based on
  407.      the name. gnus-uu is not a MIME package, so this is slightly
  408.      kludgy.
  409.  
  410.    `gnus-uu-tmp-dir'
  411.      Where gnus-uu does its work.
  412.  
  413.    `gnus-uu-do-not-unpack-archives'
  414.      Non-nil means that gnus-uu won't peek inside archives looking for
  415.      files to dispay.
  416.  
  417.    `gnus-uu-view-and-save'
  418.      Non-nil means that the user will always be asked to save a file
  419.      after viewing it.
  420.  
  421.    `gnus-uu-asynchronous' 
  422.      Non-nil means that files will be viewed asynchronously.  This can
  423.      be useful if you're viewing long .mod files, for instance, which
  424.      often takes several minutes. Note, however, that since gnus-uu
  425.      doesn't ask, and if you are viewing an archive with lots of
  426.      viewable files, you'll get them all up more or less at once,
  427.      which can be confusing, to say the least. To get gnus-uu to ask
  428.      you before viewing a file, set the `gnus-uu-ask-before-view' 
  429.      variable.
  430.  
  431.    `gnus-uu-ask-before-view'
  432.      Non-nil means that gnus-uu will ask you before viewing each file
  433.  
  434.    `gnus-uu-ignore-default-view-rules'
  435.      Non-nil means that gnus-uu will ignore the default viewing rules.
  436.  
  437.    `gnus-uu-ignore-default-archive-rules'
  438.      Non-nil means that gnus-uu will ignore the default archive
  439.      unpacking commands.
  440.  
  441.    `gnus-uu-kill-carriage-return'
  442.      Non-nil means that gnus-uu will strip all carriage returns from
  443.      articles.
  444.  
  445.    `gnus-uu-unmark-articles-not-decoded'
  446.      Non-nil means that gnus-uu will mark articles that were
  447.      unsuccessfully decoded as unread.
  448.  
  449.    `gnus-uu-output-window-height'
  450.      This variable says how tall the output buffer window is to be
  451.      when using interactive view mode.
  452.  
  453.    `gnus-uu-correct-stripped-uucode'
  454.      Non-nil means that gnus-uu will *try* to fix uuencoded files that
  455.      have had traling spaces deleted.
  456.  
  457.    `gnus-uu-use-interactive-view'
  458.      Non-nil means that gnus-uu will use interactive viewing mode.
  459.  
  460.    `gnus-uu-view-with-metamail'
  461.      Non-nil means that gnus-uu will ignore the viewing commands
  462.      defined by the rule variables and just fudge a MIME content type
  463.      based on the file name. The result will be fed to metamail for
  464.      viewing.
  465.  
  466.    `gnus-uu-save-in-digest'
  467.      Non-nil means that gnus-uu, when asked to save without decoding,
  468.      will save in digests.  If this variable is nil, gnus-uu will just
  469.      save everything in a file without any embellishments. The
  470.      digesting almost conforms to RFC1153 - no easy way to specify any
  471.      meaningful volume and issue numbers were found, so I simply
  472.      dropped them.
  473.  
  474.    `gnus-uu-post-include-before-composing'
  475.      Non-nil means that gnus-uu will ask for a file to encode before
  476.      you compose the article.  If this variable is t, you can either
  477.      include an encoded file with \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-insert-binary-in-article] or have one included for you when you 
  478.      post the article.
  479.  
  480.    `gnus-uu-post-length'
  481.      Maximum length of an article.  The encoded file will be split
  482.      into how many articles it takes to post the entire file.
  483.  
  484.    `gnus-uu-post-threaded'
  485.      Non-nil means that gnus-uu will post the encoded file in a
  486.      thread.  This may not be smart, as no other decoder I have seen
  487.      are able to follow threads when collecting uuencoded
  488.      articles. (Well, I have seen one package that does that -
  489.      gnus-uu, but somehow, I don't think that counts...) Default is
  490.      nil.
  491.  
  492.    `gnus-uu-post-separate-description'
  493.      Non-nil means that the description will be posted in a separate
  494.      article.  The first article will typically be numbered (0/x). If
  495.      this variable is nil, the description the user enters will be
  496.      included at the beginning of the first article, which will be
  497.      numbered (1/x). Default is t.
  498. "
  499.   (interactive)
  500.   )
  501.  
  502. ;; Default viewing action rules
  503.  
  504. (defvar gnus-uu-default-view-rules 
  505.   (list 
  506.    '("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv")
  507.    '("\\.tga$" "tgatoppm %s | xv -")
  508.    '("\\.te?xt$\\|\\.doc$\\|read.*me" "xterm -e less")
  509.    '("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$" 
  510.      "sox -v .5 %s -t .au -u - > /dev/audio")
  511.    '("\\.au$" "cat %s > /dev/audio")
  512.    '("\\.mod$" "str32")
  513.    '("\\.ps$" "ghostview")
  514.    '("\\.dvi$" "xdvi")
  515.    '("\\.[1-6]$" "xterm -e man -l")
  516.    '("\\.html$" "xmosaic")
  517.    '("\\.mpe?g$" "mpeg_play")
  518.    '("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\)$" "xanim")
  519.    '("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$" 
  520.      "gnus-uu-archive"))
  521.  
  522.   "Default actions to be taken when the user asks to view a file.  
  523. To change the behaviour, you can either edit this variable or set
  524. `gnus-uu-user-view-rules' to something useful.
  525.  
  526. For example:
  527.  
  528. To make gnus-uu use 'xli' to display JPEG and GIF files, put the
  529. following in your .emacs file
  530.  
  531.   (setq gnus-uu-user-view-rules (list '(\"jpg$\\\\|gif$\" \"xli\")))
  532.  
  533. Both these variables are lists of lists with two string elements. The
  534. first string is a regular expression. If the file name matches this
  535. regular expression, the command in the second string is executed with
  536. the file as an argument.
  537.  
  538. If the command string contains \"%s\", the file name will be inserted
  539. at that point in the command string. If there's no \"%s\" in the
  540. command string, the file name will be appended to the command string
  541. before executing.
  542.  
  543. There are several user variables to tailor the behaviour of gnus-uu to
  544. your needs. First we have `gnus-uu-user-view-rules', which is the
  545. variable gnus-uu first consults when trying to decide how to view a
  546. file. If this variable contains no matches, gnus-uu examines the
  547. default rule vaiable provided in this package. If gnus-uu finds no
  548. match here, it uses `gnus-uu-user-view-rules-end' to try to make a
  549. match.
  550.  
  551. Unless, of course, you are using the interactive view mode. Then
  552. `gnus-uu-user-interactive-view-rules' and
  553. `gnus-uu-user-interactive-view-rules-end' will be used instead.")
  554.  
  555. (defvar gnus-uu-user-view-rules nil 
  556.   "Variable detailing what actions are to be taken to view a file.
  557. See the documentation on the `gnus-uu-default-view-rules' variable for 
  558. details.")
  559.  
  560. (defvar gnus-uu-user-view-rules-end nil
  561.   "Variable saying what actions are to be taken if no rule matched the file name.
  562. See the documentation on the `gnus-uu-default-view-rules' variable for 
  563. details.")
  564.  
  565. (defvar gnus-uu-user-interactive-view-rules nil
  566.   "Variable detailing what actions are to be taken to view a file when using interactive mode.
  567. See the documentation on the `gnus-uu-default-view-rules' variable for 
  568. details.")
  569.  
  570. (defvar gnus-uu-user-interactive-view-rules-end nil
  571.   "Variable saying what actions are to be taken if no rule matched the file name when using interactive mode.
  572. See the documentation on the `gnus-uu-default-view-rules' variable for 
  573. details.")
  574.  
  575. (defvar gnus-uu-default-interactive-view-rules-begin
  576.   (list
  577.    '("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed s/\r//g")
  578.    '("\\.pas$" "cat %s | sed s/\r//g")
  579.    ))
  580.  
  581. (defvar gnus-uu-default-interactive-view-rules-end
  582.   (list
  583.    '(".*" "file")))
  584.  
  585. ;; Default unpacking commands
  586.  
  587. (defvar gnus-uu-default-archive-rules 
  588.   (list '("\\.tar$" "tar xf")
  589.     '("\\.zip$" "unzip -o")
  590.     '("\\.ar$" "ar x")
  591.     '("\\.arj$" "unarj x")
  592.     '("\\.zoo$" "zoo -e")
  593.     '("\\.\\(lzh\\|lha\\)$" "lha x")
  594.     '("\\.Z$" "uncompress")
  595.     '("\\.gz$" "gunzip")
  596.     '("\\.arc$" "arc -x"))
  597.   )
  598.  
  599. (defvar gnus-uu-destructive-archivers 
  600.   (list "uncompress" "gunzip"))
  601.  
  602. (defvar gnus-uu-user-archive-rules nil
  603.   "A list that can be set to override the default archive unpacking commands.
  604. To use, for instance, 'untar' to unpack tar files and 'zip -x' to
  605. unpack zip files, say the following:
  606.   (setq gnus-uu-user-archive-rules 
  607.     (list '(\"\\\\.tar$\" \"untar\")
  608.           '(\"\\\\.zip$\" \"zip -x\")))")
  609.  
  610. (defvar gnus-uu-ignore-files-by-name nil
  611.   "A regular expression saying what files should not be viewed based on name.
  612. If, for instance, you want gnus-uu to ignore all .au and .wav files, 
  613. you could say something like
  614.  
  615.   (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
  616.  
  617. Note that this variable can be used in conjunction with the
  618. `gnus-uu-ignore-files-by-type' variable.")
  619.  
  620. (defvar gnus-uu-ignore-files-by-type nil
  621.   "A regular expression saying what files that shouldn't be viewed, based on MIME file type.
  622. If, for instance, you want gnus-uu to ignore all audio files and all mpegs, 
  623. you could say something like
  624.  
  625.   (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
  626.  
  627. Note that this variable can be used in conjunction with the
  628. `gnus-uu-ignore-files-by-name' variable.")
  629.  
  630. ;; Pseudo-MIME support
  631.  
  632. (defconst gnus-uu-ext-to-mime-list
  633.   (list '("\\.gif$" "image/gif")
  634.     '("\\.jpe?g$" "image/jpeg")
  635.     '("\\.tiff?$" "image/tiff")
  636.     '("\\.xwd$" "image/xwd")
  637.     '("\\.pbm$" "image/pbm")
  638.     '("\\.pgm$" "image/pgm")
  639.     '("\\.ppm$" "image/ppm")
  640.     '("\\.xbm$" "image/xbm")
  641.     '("\\.pcx$" "image/pcx")
  642.     '("\\.tga$" "image/tga")
  643.     '("\\.ps$" "image/postscript")
  644.     '("\\.fli$" "video/fli")
  645.     '("\\.wav$" "audio/wav")
  646.     '("\\.aiff$" "audio/aiff")
  647.     '("\\.hcom$" "audio/hcom")
  648.     '("\\.voc$" "audio/voc")
  649.     '("\\.smp$" "audio/smp")
  650.     '("\\.mod$" "audio/mod")
  651.     '("\\.dvi$" "image/dvi")
  652.     '("\\.mpe?g$" "video/mpeg")
  653.     '("\\.au$" "audio/basic")
  654.     '("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
  655.     '("\\.\\(c\\|h\\)$" "text/source")
  656.     '("read.*me" "text/plain")
  657.     '("\\.html$" "text/html")
  658.     '("\\.bat$" "text/bat")
  659.     '("\\.[1-6]$" "text/man")
  660.     '("\\.flc$" "video/flc")
  661.     '("\\.rle$" "video/rle")
  662.     '("\\.pfx$" "video/pfx")
  663.     '("\\.avi$" "video/avi")
  664.     '("\\.sme$" "video/sme")
  665.     '("\\.rpza$" "video/prza")
  666.     '("\\.dl$" "video/dl")
  667.     '("\\.qt$" "video/qt")
  668.     '("\\.rsrc$" "video/rsrc")
  669.     '("\\..*$" "unknown/unknown")))
  670.  
  671. ;; Various variables users may set 
  672.  
  673. (defvar gnus-uu-tmp-dir "/tmp/" 
  674.   "Variable saying where gnus-uu is to do its work.
  675. Default is \"/tmp/\".")
  676.  
  677. (defvar gnus-uu-do-not-unpack-archives nil 
  678.   "Non-nil means that gnus-uu won't peek inside archives looking for files to dispay. 
  679. Default is nil.")
  680.  
  681. (defvar gnus-uu-view-and-save nil 
  682.   "Non-nil means that the user will always be asked to save a file after viewing it.
  683. If the variable is nil, the suer will only be asked to save if the
  684. viewing is unsuccessful. Default is nil.")
  685.  
  686. (defvar gnus-uu-asynchronous nil
  687.   "Non-nil means that files will be viewed asynchronously.
  688. Default is nil.")
  689.  
  690. (defvar gnus-uu-ask-before-view nil
  691.   "Non-nil means that gnus-uu will ask you before viewing each file. 
  692. Especially useful when `gnus-uu-asynchronous' is set. Default is
  693. nil.")
  694.  
  695. (defvar gnus-uu-ignore-default-view-rules nil
  696.   "Non-nil means that gnus-uu will ignore the default viewing rules.
  697. Only the user viewing rules will be consulted. Default is nil.")
  698.  
  699. (defvar gnus-uu-ignore-default-archive-rules nil 
  700.   "Non-nil means that gnus-uu will ignore the default archive unpacking commands.  
  701. Only the user unpacking commands will be consulted. Default is nil.")
  702.  
  703. (defvar gnus-uu-kill-carriage-return t
  704.   "Non-nil means that gnus-uu will strip all carriage returns from articles.
  705. Default is t.")
  706.  
  707. (defvar gnus-uu-view-with-metamail nil
  708.   "Non-nil means that files will be viewed with metamail.
  709. The gnus-uu viewing functions will be ignored and gnus-uu will try
  710. to guess at a content-type based on file name suffixes. Default
  711. it nil.")
  712.  
  713. (defvar gnus-uu-unmark-articles-not-decoded nil
  714.   "Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread. 
  715. Default is nil.")
  716.  
  717. (defvar gnus-uu-output-window-height 20 
  718.   "This variable says how tall the output buffer window is to be when using interactive view mode. 
  719. Change it at your convenience. Default is 20.")
  720.  
  721. (defvar gnus-uu-correct-stripped-uucode nil
  722.   "Non-nil means that gnus-uu will *try* to fix uuencoded files that have had traling spaces deleted. 
  723. Default is nil.")
  724.  
  725. (defvar gnus-uu-use-interactive-view nil
  726.   "Non-nil means that gnus-uu will use interactive viewing mode.
  727. Gnus-uu will create a special buffer where the user may choose
  728. interactively which files to view and how. Default is nil.")
  729.  
  730. (defvar gnus-uu-save-in-digest nil
  731.   "Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
  732. If this variable is nil, gnus-uu will just save everything in a 
  733. file without any embellishments. The digesting almost conforms to RFC1153 -
  734. no easy way to specify any meaningful volume and issue numbers were found, 
  735. so I simply dropped them.")
  736.  
  737.  
  738. ;; Internal variables
  739.  
  740. (defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
  741. (defconst gnus-uu-end-string "^end[ \t]*$")
  742.  
  743. (defconst gnus-uu-body-line "^M")
  744. (let ((i 61))
  745.   (while (> (setq i (1- i)) 0)
  746.     (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
  747.   (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
  748.  
  749. ;"^M.............................................................?$"
  750.  
  751. (defconst gnus-uu-shar-begin-string "^#! */bin/sh")
  752.  
  753. (defvar gnus-uu-shar-file-name nil)
  754. (defconst gnus-uu-shar-name-marker "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
  755. (defvar gnus-uu-shar-directory nil)
  756.  
  757. (defvar gnus-uu-file-name nil)
  758. (defvar gnus-uu-list-of-files-decoded nil)
  759. (defconst gnus-uu-uudecode-process nil)
  760.  
  761. (defvar gnus-uu-interactive-file-list nil)
  762. (defvar gnus-uu-marked-article-list nil)
  763. (defvar gnus-uu-generated-file-list nil)
  764. (defvar gnus-uu-work-dir nil)
  765.  
  766. (defconst gnus-uu-interactive-buffer-name "*gnus-uu interactive*")
  767. (defconst gnus-uu-output-buffer-name "*Gnus UU Output*")
  768. (defconst gnus-uu-result-buffer "*Gnus UU Result Buffer*")
  769.  
  770. (defconst gnus-uu-highest-article-number 1)
  771.  
  772. ;; Interactive functions
  773.  
  774. ;; UUdecode and view
  775.  
  776. (defun gnus-uu-decode-and-view ()
  777.   "UUdecodes and 'views' (if possible) the resulting file.
  778. 'Viewing' can be any action at all, as defined in the
  779. `gnus-uu-file-action-list' variable. Running 'xv' on gifs and 'cat
  780. >/dev/audio' on au files are popular actions. If the file can't be
  781. viewed, the user is asked if she would like to save the file instead."
  782.   (interactive) 
  783.   (gnus-uu-decode-and-view-or-save t nil))
  784.  
  785. (defun gnus-uu-decode-and-save ()
  786.   "Decodes and saves the resulting file."
  787.   (interactive)
  788.   (gnus-uu-decode-and-view-or-save nil nil))
  789.  
  790. (defun gnus-uu-marked-decode-and-view ()
  791.   "Decodes and views articles marked.
  792. The marked equivalent to `gnus-uu-decode-and-view'."
  793.   (interactive)
  794.   (gnus-uu-decode-and-view-or-save t t))
  795.  
  796. (defun gnus-uu-marked-decode-and-save ()
  797.   "Decodes and saves articles marked.
  798. The marked equivalent to `gnus-uu-decode-and-save'."
  799.   (interactive)
  800.   (gnus-uu-decode-and-view-or-save nil t))
  801.       
  802.  
  803. ;; Unshar and view
  804.  
  805. (defun gnus-uu-shar-and-view ()
  806.   "Unshars and views articles.
  807. The shar equivalent of `gnus-uu-decode-and-view'."
  808.   (interactive)
  809.   (gnus-uu-unshar-and-view-or-save t nil))
  810.  
  811. (defun gnus-uu-shar-and-save ()
  812.   "Unshars and saves files.
  813. The shar equivalent to `gnus-uu-decode-and-save'."
  814.   (interactive)
  815.   (gnus-uu-unshar-and-view-or-save nil nil))
  816.  
  817. (defun gnus-uu-marked-shar-and-view ()
  818.   "Unshars and views articles marked.
  819. The marked equivalent to `gnus-uu-shar-and-view'."
  820.   (interactive)
  821.   (gnus-uu-unshar-and-view-or-save t t))
  822.  
  823. (defun gnus-uu-marked-shar-and-save ()
  824.   "Unshars and saves articles marked.
  825. The marked equivalent to `gnus-uu-shar-and-save'."
  826.   (interactive)
  827.   (gnus-uu-unshar-and-view-or-save nil t))
  828.  
  829. ;; Threaded decode
  830.  
  831. (defun gnus-uu-threaded-decode-and-view ()
  832.   "Decodes and saves the resulting file."
  833.   (interactive)
  834.   (gnus-uu-threaded-decode-and-view-or-save t))
  835.  
  836. (defun gnus-uu-threaded-decode-and-save ()
  837.   "Decodes and saves the resulting file."
  838.   (interactive)
  839.   (gnus-uu-threaded-decode-and-view-or-save nil))
  840.  
  841. (defun gnus-uu-threaded-multi-decode-and-view ()
  842.   "Decodes and saves the resulting file."
  843.   (interactive)
  844.   (gnus-uu-threaded-multi-decode-and-view-or-save t))
  845.  
  846. (defun gnus-uu-threaded-multi-decode-and-save ()
  847.   "Decodes and saves the resulting file."
  848.   (interactive)
  849.   (gnus-uu-threaded-multi-decode-and-view-or-save nil))
  850.  
  851. (defun gnus-uu-threaded-decode-and-view-or-save (&optional view)
  852.   (gnus-uu-unmark-all-articles)
  853.   (gnus-uu-mark-thread)
  854.   (gnus-uu-decode-and-view-or-save view t))
  855.  
  856. (defun gnus-uu-threaded-multi-decode-and-view-or-save (view)
  857.   (let (type)
  858.     (message "Decode type: [u]udecode, (s)har, s(a)ve, (b)inhex: ")
  859.     (setq type (read-char))
  860.     (if (not (or (= type ?u) (= type ?s) (= type ?b) (= type ?a)))
  861.     (error "No such decoding method '%c'" type))
  862.     
  863.     (gnus-uu-unmark-all-articles)
  864.     (gnus-uu-mark-thread)
  865.  
  866.     (if (= type ?\r) (setq type ?u))
  867.     (cond ((= type ?u) (gnus-uu-decode-and-view-or-save view t))
  868.       ((= type ?s) (gnus-uu-unshar-and-view-or-save view t))
  869.       ((= type ?b) (gnus-uu-binhex-and-save view t))
  870.       ((= type ?a) (gnus-uu-save-articles view t)))))
  871.     
  872.  
  873. ;; Toggle commands      
  874.  
  875. (defun gnus-uu-toggle-asynchronous ()
  876.   "This function toggles asynchronous viewing."
  877.   (interactive)
  878.   (if (setq gnus-uu-asynchronous (not gnus-uu-asynchronous))
  879.       (message "gnus-uu will now view files asynchronously")
  880.     (message "gnus-uu will now view files synchronously")))
  881.  
  882. (defun gnus-uu-toggle-query ()
  883.   "This function toggles whether to ask before viewing or not."
  884.   (interactive)
  885.   (if (setq gnus-uu-ask-before-view (not gnus-uu-ask-before-view))
  886.       (message "gnus-uu will now ask before viewing")
  887.     (message "gnus-uu will now view without asking first")))
  888.  
  889. (defun gnus-uu-toggle-always-ask ()
  890.   "This function toggles whether to always ask to save a file after viewing."
  891.   (interactive)
  892.   (if (setq gnus-uu-view-and-save (not gnus-uu-view-and-save))
  893.       (message "gnus-uu will now ask to save the file after viewing")
  894.     (message "gnus-uu will now not ask to save after successful viewing")))
  895.  
  896. (defun gnus-uu-toggle-interactive-view ()
  897.   "This function toggles whether to use interactive view."
  898.   (interactive)
  899.   (if (setq gnus-uu-use-interactive-view (not gnus-uu-use-interactive-view))
  900.       (message "gnus-uu will now use interactive view")
  901.     (message "gnus-uu will now use non-interactive view")))
  902.  
  903. (defun gnus-uu-toggle-unmark-undecoded ()
  904.   "This function toggles whether to unmark articles not decoded."
  905.   (interactive)
  906.   (if (setq gnus-uu-unmark-articles-not-decoded 
  907.         (not gnus-uu-unmark-articles-not-decoded))
  908.       (message "gnus-uu will now unmark articles not decoded")
  909.     (message "gnus-uu will now not unmark articles not decoded")))
  910.  
  911. (defun gnus-uu-toggle-kill-carriage-return ()
  912.   "This function toggles the stripping of carriage returns from the articles."
  913.   (interactive)
  914.   (if (setq gnus-uu-kill-carriage-return (not gnus-uu-kill-carriage-return))
  915.       (message "gnus-uu will now strip carriage returns")
  916.     (message "gnus-uu won't strip carriage returns")))
  917.  
  918. (defun gnus-uu-toggle-view-with-metamail ()
  919.   "This function toggles whether to view files with metamail."
  920.   (interactive)
  921.   (if (setq gnus-uu-view-with-metamail (not gnus-uu-view-with-metamail))
  922.       (message "gnus-uu will now view with metamail")
  923.     (message "gnus-uu will now view with the gnus-uu viewing functions")))
  924.  
  925. (defun gnus-uu-toggle-correct-stripped-uucode ()
  926.   "This function toggles whether to correct stripped uucode."
  927.   (interactive)
  928.   (if (setq gnus-uu-correct-stripped-uucode 
  929.         (not gnus-uu-correct-stripped-uucode))
  930.       (message "gnus-uu will now correct stripped uucode")
  931.     (message "gnus-uu won't check and correct stripped uucode")))
  932.  
  933. (defun gnus-uu-toggle-any-variable ()
  934.   "This function ask what variable the user wants to toggle."
  935.   (interactive)
  936.   (let (rep)
  937.     (message "(a)sync, (q)uery, (p)ask, (k)ill CR, (i)nteract, (u)nmark, (c)orrect, (m)eta")
  938.     (setq rep (read-char))
  939.     (if (= rep ?a)
  940.     (gnus-uu-toggle-asynchronous))
  941.     (if (= rep ?q)
  942.     (gnus-uu-toggle-query))
  943.     (if (= rep ?p)
  944.     (gnus-uu-toggle-always-ask))
  945.     (if (= rep ?k)
  946.     (gnus-uu-toggle-kill-carriage-return))
  947.     (if (= rep ?u)
  948.     (gnus-uu-toggle-unmark-undecoded))
  949.     (if (= rep ?c)
  950.     (gnus-uu-toggle-correct-stripped-uucode))
  951.     (if (= rep ?m)
  952.     (gnus-uu-toggle-view-with-metamail))
  953.     (if (= rep ?i)
  954.     (gnus-uu-toggle-interactive-view))))
  955.  
  956.  
  957. ;; Misc interactive functions
  958.  
  959. (defun gnus-uu-decode-and-show-in-buffer ()
  960.   "Uudecodes the current article and displays the result in a buffer.
  961. Might be useful if someone has, for instance, some text uuencoded in
  962. their sigs. (Stranger things have happened.)"
  963.   (interactive)
  964.   (gnus-uu-initialize)
  965.   (let ((uu-buffer (get-buffer-create gnus-uu-output-buffer-name))
  966.     file-name)
  967.     (save-excursion
  968.       (and 
  969.        (gnus-summary-select-article)
  970.        (gnus-uu-grab-articles (list gnus-current-article) 
  971.                   'gnus-uu-uustrip-article-as)
  972.        (setq file-name (concat gnus-uu-work-dir gnus-uu-file-name))
  973.        (progn
  974.      (save-excursion
  975.        (set-buffer uu-buffer)
  976.        (erase-buffer)
  977.        (insert-file-contents file-name))
  978.      (set-window-buffer (get-buffer-window gnus-article-buffer) 
  979.                 uu-buffer)
  980.      (message "Showing file %s in buffer" file-name)
  981.      (delete-file file-name))))))
  982.  
  983. (defun gnus-uu-edit-begin-line ()
  984.   "Edit the begin line of the current article."
  985.   (interactive)
  986.   (let ((buffer-read-only nil)
  987.     begin b)
  988.     (save-excursion
  989.       (gnus-summary-select-article)
  990.       (set-buffer gnus-article-buffer)
  991.       (goto-line 1)
  992.       (if (not (re-search-forward "begin " nil t))
  993.       (error "No begin line in the current article")
  994.     (beginning-of-line)
  995.     (setq b (point))
  996.     (end-of-line)
  997.     (setq begin (buffer-substring b (point)))
  998.     (setq begin (read-string "" begin))
  999.     (setq buffer-read-only nil)
  1000.     (delete-region b (point))
  1001.     (insert-string begin)))))
  1002.  
  1003.  
  1004. ;; Multi functions
  1005.  
  1006. (defun gnus-uu-multi-decode-and-view ()
  1007.   "Choose a method of decoding and then decode and view.
  1008. This function lets the user decide what method to use for decoding.
  1009. Other than that, it's equivalent to the other decode-and-view
  1010. functions."
  1011.   (interactive)
  1012.   (gnus-uu-multi-decode-and-view-or-save t nil))
  1013.  
  1014. (defun gnus-uu-multi-decode-and-save ()
  1015.   "Choose a method of decoding and then decode and save.
  1016. This function lets the user decide what method to use for decoding.
  1017. Other than that, it's equivalent to the other decode-and-save 
  1018. functions."
  1019.   (interactive)
  1020.   (gnus-uu-multi-decode-and-view-or-save nil nil))
  1021.  
  1022. (defun gnus-uu-marked-multi-decode-and-view ()
  1023.   "Choose a method of decoding and then decode and view the marked articles.
  1024. This function lets the user decide what method to use for decoding.
  1025. Other than that, it's equivalent to the other marked decode-and-view 
  1026. functions."
  1027.   (interactive)
  1028.   (gnus-uu-multi-decode-and-view-or-save t t))
  1029.  
  1030. (defun gnus-uu-marked-multi-decode-and-save ()
  1031.   "Choose a method of decoding and then decode and save the marked articles.
  1032. This function lets the user decide what method to use for decoding.
  1033. Other than that, it's equivalent to the other marked decode-and-save 
  1034. functions."
  1035.   (interactive)
  1036.   (gnus-uu-multi-decode-and-view-or-save t t))
  1037.  
  1038. (defun gnus-uu-multi-decode-and-view-or-save (view marked)
  1039.   (let (type)
  1040.     (message "[u]udecode, (s)har, s(a)ve, (b)inhex: ")
  1041.     (setq type (read-char))
  1042.     (if (= type ?\r) (setq type ?u))
  1043.     (cond ((= type ?u) (gnus-uu-decode-and-view-or-save view marked))
  1044.       ((= type ?s) (gnus-uu-unshar-and-view-or-save view marked))
  1045.       ((= type ?b) (gnus-uu-binhex-and-save view marked))
  1046.       ((= type ?a) (gnus-uu-save-articles view marked))
  1047.       (t (error "Unknown decode method '%c'." type)))))
  1048.  
  1049.  
  1050. ;; "All articles" commands
  1051.  
  1052. (defconst gnus-uu-rest-of-articles nil)
  1053. (defvar gnus-uu-current-save-dir nil)
  1054.  
  1055. (defun gnus-uu-decode-and-view-all-articles (arg &optional unread)
  1056.   "Try to decode all articles and view the result.
  1057. ARG delimits the number of files to be decoded."
  1058.   (interactive "p")
  1059.   (if (not (setq gnus-uu-marked-article-list 
  1060.          (nreverse (gnus-uu-get-list-of-articles 
  1061.                 "^." nil unread t))))
  1062.       (error "No%s articles to be decoded" (if unread " unread" "")))
  1063.   (gnus-uu-decode-and-view-or-save t t nil (if (> arg 1) arg nil)))
  1064.  
  1065. (defun gnus-uu-decode-and-view-all-unread-articles (arg)
  1066.   "Try to decode all unread articles and view the result.
  1067. ARG delimits the number of files to be decoded."
  1068.   (interactive "p")
  1069.   (gnus-uu-decode-and-view-all-articles arg t))
  1070.  
  1071. (defun gnus-uu-decode-and-save-all-unread-articles (arg)
  1072.   "Try to decode all unread articles and saves the result.
  1073. This function reads all unread articles in the current group and sees
  1074. whether it can uudecode the articles. The user will be prompted for an
  1075. directory to put the resulting (if any) files.
  1076. ARG delimits the number of files to be decoded."
  1077.   (interactive "p")
  1078.   (gnus-uu-decode-and-save-articles arg t t))
  1079.  
  1080. (defun gnus-uu-decode-and-save-all-articles (arg)
  1081.   "Try to decode all articles and saves the result.
  1082. Does the same as `gnus-uu-decode-and-save-all-unread-articles', except
  1083. that it grabs all articles visible, unread or not.
  1084. ARG delimits the number of files to be decoded."
  1085.   (interactive "p")
  1086.   (gnus-uu-decode-and-save-articles arg nil t))
  1087.  
  1088. (defun gnus-uu-decode-and-save-articles (arg &optional unread unmark)
  1089.   (let (dir)
  1090.     (if (not (setq gnus-uu-marked-article-list 
  1091.            (nreverse (gnus-uu-get-list-of-articles 
  1092.                   "^." nil unread t))))
  1093.     (error "No%s articles to be decoded." (if unread " unread" ""))
  1094.       (setq dir (gnus-uu-read-directory "Where do you want the files? "))
  1095.       (gnus-uu-decode-and-view-or-save nil t dir (if (> arg 1) arg nil))
  1096.       (message "Saved."))))
  1097.  
  1098.  
  1099. ;; Work functions
  1100.  
  1101. ; All the interactive uudecode/view/save/marked functions are interfaces
  1102. ; to this function, which does the rest.
  1103. (defun gnus-uu-decode-and-view-or-save (view marked &optional save-dir limit)
  1104.   (gnus-uu-initialize)
  1105.   (let (decoded)
  1106.     (save-excursion
  1107.       (if (gnus-uu-decode-and-strip nil marked limit)
  1108.       (progn
  1109.         (setq decoded t)
  1110.         (if view 
  1111.         (gnus-uu-view-directory gnus-uu-work-dir 
  1112.                     gnus-uu-use-interactive-view)
  1113.           (gnus-uu-save-directory gnus-uu-work-dir save-dir save-dir)
  1114.           (gnus-uu-check-for-generated-files)))))
  1115.  
  1116.     (gnus-uu-summary-next-subject)
  1117.  
  1118.     (if (and gnus-uu-use-interactive-view view decoded)
  1119.     (gnus-uu-do-interactive))
  1120.  
  1121.     (if (or (not view) (not gnus-uu-use-interactive-view) (not decoded))
  1122.     (gnus-uu-clean-up))))
  1123.  
  1124. ; Unshars and views/saves marked/unmarked articles.
  1125. (defun gnus-uu-unshar-and-view-or-save (view marked)
  1126.   (gnus-uu-initialize)
  1127.   (let (tar-file files decoded)
  1128.     (save-excursion
  1129.       (setq gnus-uu-shar-directory 
  1130.         (make-temp-name (concat gnus-uu-tmp-dir "gnusuush")))
  1131.       (make-directory gnus-uu-shar-directory)
  1132.       (gnus-uu-add-file gnus-uu-shar-directory)
  1133.       (if (gnus-uu-decode-and-strip t marked)
  1134.       (progn
  1135.         (setq decoded t)
  1136.         (setq files (directory-files gnus-uu-shar-directory t))
  1137.         (setq gnus-uu-generated-file-list
  1138.           (append files gnus-uu-generated-file-list))
  1139.         (if (> (length files) 3)
  1140.         (progn 
  1141.           (setq tar-file 
  1142.             (concat
  1143.              (make-temp-name (concat gnus-uu-tmp-dir "gnusuuar"))
  1144.              ".tar"))
  1145.           (gnus-uu-add-file tar-file)
  1146.           (call-process 
  1147.            "sh" nil 
  1148.            (get-buffer-create gnus-uu-output-buffer-name) nil "-c" 
  1149.            (format "cd %s ; tar cf %s * ; cd .. ; rm -r %s" 
  1150.                gnus-uu-shar-directory tar-file
  1151.                gnus-uu-shar-directory))
  1152.           (if view
  1153.               (gnus-uu-view-file tar-file)
  1154.             (gnus-uu-save-file tar-file)))
  1155.           (if view
  1156.           (gnus-uu-view-file (elt files 2))
  1157.         (gnus-uu-save-file (elt files 2)))))))
  1158.  
  1159.     (gnus-uu-summary-next-subject)
  1160.  
  1161.     (if (and gnus-uu-use-interactive-view view decoded)
  1162.     (gnus-uu-do-interactive))
  1163.  
  1164.     (if (or (not gnus-uu-use-interactive-view) (not decoded))
  1165.     (gnus-uu-clean-up))))
  1166.  
  1167.  
  1168. ;; Functions for saving and possibly digesting articles without
  1169. ;; any decoding.
  1170.  
  1171. (defconst gnus-uu-saved-article-name nil)
  1172.  
  1173. ; VIEW isn't used, but is here anyway, to provide similar interface to
  1174. ; the other related functions.  If MARKED is non-nil, the list of
  1175. ; marked articles is used.  If NO-SAVE is non-nil, the articles aren't
  1176. ; actually saved in a permanent location, but the collecting is done
  1177. ; and a temporary file with the result is returned.
  1178. (defun gnus-uu-save-articles (view marked &optional no-save)
  1179.   (let (list-of-articles)
  1180.     (save-excursion
  1181.       (gnus-uu-initialize)
  1182.       (if (not marked)
  1183.       (setq list-of-articles (gnus-uu-get-list-of-articles))
  1184.     (setq list-of-articles (reverse gnus-uu-marked-article-list))
  1185.     (setq gnus-uu-marked-article-list nil))
  1186.  
  1187.       (if (not list-of-articles)
  1188.       (error "No list of articles"))
  1189.  
  1190.       (setq gnus-uu-saved-article-name 
  1191.         (concat gnus-uu-work-dir 
  1192.             (if no-save
  1193.             gnus-newsgroup-name
  1194.               (read-file-name "Enter file name: " gnus-newsgroup-name
  1195.                       gnus-newsgroup-name))))
  1196.       (gnus-uu-add-file gnus-uu-saved-article-name)
  1197.       (if (and (gnus-uu-grab-articles list-of-articles 'gnus-uu-save-article t)
  1198.            (not no-save))
  1199.       (gnus-uu-save-file gnus-uu-saved-article-name)
  1200.     gnus-uu-saved-article-name))))
  1201.  
  1202. ; Function called by gnus-uu-grab-articles to treat each article.
  1203. (defun gnus-uu-save-article (buffer in-state)
  1204.   (if (not gnus-uu-save-in-digest)
  1205.       (save-excursion
  1206.     (set-buffer buffer)
  1207.     (write-region 1 (point-max) gnus-uu-saved-article-name t)
  1208.     (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
  1209.           ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name 'begin 'end))
  1210.           ((eq in-state 'last) (list 'end))
  1211.           (t (list 'middle))))
  1212.     (let (beg subj name headers headline sorthead body end-string state)
  1213.       (string-match "/\\([^/]*\\)$" gnus-uu-saved-article-name)
  1214.       (setq name (substring gnus-uu-saved-article-name (match-beginning 1)
  1215.                 (match-end 1)))
  1216.       (if (or (eq in-state 'first) 
  1217.           (eq in-state 'first-and-last))
  1218.       (progn 
  1219.         (setq state (list 'begin))
  1220.         (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
  1221.                 (erase-buffer))
  1222.         (save-excursion 
  1223.           (set-buffer (get-buffer-create "*gnus-uu-pre*"))
  1224.           (erase-buffer)
  1225.           (insert (format 
  1226.                "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
  1227.                (current-time-string) name name))))
  1228.     (if (not (eq in-state 'end))
  1229.         (setq state (list 'middle))))
  1230.       (save-excursion
  1231.     (set-buffer (get-buffer "*gnus-uu-body*"))
  1232.     (goto-char (setq beg (point-max)))
  1233.     (save-excursion
  1234.       (save-restriction
  1235.         (set-buffer buffer)
  1236.         (goto-char 1)
  1237.         (re-search-forward "\n\n")
  1238.         (setq body (buffer-substring (1- (point)) (point-max)))
  1239.         (narrow-to-region 1 (point))
  1240.         (setq headers (list "Date:" "From:" "To:" "Cc:" "Subject:"
  1241.                 "Message-ID:" "Keywords:" "Summary:"))
  1242.         (while headers
  1243.           (setq headline (car headers))
  1244.           (setq headers (cdr headers))
  1245.           (goto-char 1)
  1246.           (if (re-search-forward (concat "^" headline ".*$") nil t)
  1247.           (setq sorthead 
  1248.             (concat sorthead (buffer-substring 
  1249.                       (match-beginning 0)
  1250.                       (match-end 0)) "\n"))))
  1251.         (widen)))
  1252.     (insert sorthead)(goto-char (point-max))
  1253.     (insert body)(goto-char (point-max))
  1254.     (insert (concat "\n" (make-string 30 ?-) "\n\n"))
  1255.     (goto-char beg)
  1256.     (if (re-search-forward "^Subject: \\(.*\\)$" nil t)
  1257.         (progn
  1258.           (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
  1259.           (save-excursion 
  1260.         (set-buffer (get-buffer "*gnus-uu-pre*"))
  1261.         (insert (format "   %s\n" subj))))))
  1262.       (if (or (eq in-state 'last)
  1263.           (eq in-state 'first-and-last))
  1264.       (progn
  1265.         (save-excursion
  1266.           (set-buffer (get-buffer "*gnus-uu-pre*"))
  1267.           (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
  1268.           (write-region 1 (point-max) gnus-uu-saved-article-name))
  1269.         (save-excursion
  1270.           (set-buffer (get-buffer "*gnus-uu-body*"))
  1271.           (goto-char (point-max))
  1272.           (insert 
  1273.            (concat (setq end-string (format "End of %s Digest" name)) 
  1274.                "\n"))
  1275.           (insert (concat (make-string (length end-string) ?*) "\n"))
  1276.           (write-region 1 (point-max) gnus-uu-saved-article-name t))
  1277.         (kill-buffer (get-buffer "*gnus-uu-pre*"))
  1278.         (kill-buffer (get-buffer "*gnus-uu-body*"))
  1279.         (setq state (cons 'end state))))
  1280.       (if (memq 'begin state)
  1281.       (cons gnus-uu-saved-article-name state)
  1282.     state))))
  1283.  
  1284.  
  1285. ;; Digest and forward articles
  1286.  
  1287. (autoload 'gnus-mail-forward-using-mail "gnusmail"
  1288.       "Forward the current message to another user." t)
  1289. (autoload 'gnus-mail-forward-using-mhe "gnusmail"
  1290.       "Forward the current message to another user." t)
  1291.  
  1292. (defun gnus-uu-digest-and-forward (&optional marked)
  1293.   "Digests and forwards all articles in this series."
  1294.   (interactive)
  1295.   (let ((gnus-uu-save-in-digest t)
  1296.     file buf)
  1297.     (setq file (gnus-uu-save-articles nil marked t))
  1298.     (switch-to-buffer (setq buf (get-buffer-create "*gnus-uu-forward*")))
  1299.     (erase-buffer)
  1300.     (delete-other-windows)
  1301.     (erase-buffer)
  1302.     (insert-file file)
  1303.     (goto-char 1)
  1304.     (bury-buffer buf)
  1305.     (funcall gnus-mail-forward-method)))
  1306.  
  1307. (defun gnus-uu-marked-digest-and-forward (&optional marked)
  1308.   "Digests and forwards all marked articles."
  1309.   (interactive)
  1310.   (gnus-uu-digest-and-forward t))
  1311.  
  1312.  
  1313. ;; Binhex treatment - not very advanced. 
  1314.  
  1315. (defconst gnus-uu-binhex-body-line 
  1316.   "^[^:]...............................................................$")
  1317. (defconst gnus-uu-binhex-begin-line 
  1318.   "^:...............................................................$")
  1319. (defconst gnus-uu-binhex-end-line
  1320.   ":$")
  1321. (defvar gnus-uu-binhex-article-name nil)
  1322.  
  1323. ; This just concatenates and strips stuff from binhexed articles.
  1324. ; No actual unbinhexing takes place. VIEW is ignored.
  1325. (defun gnus-uu-binhex-and-save (view marked)
  1326.   (gnus-uu-initialize)
  1327.   (let (list-of-articles)
  1328.     (save-excursion
  1329.       (if (not marked)
  1330.       (setq list-of-articles (gnus-uu-get-list-of-articles))
  1331.     (setq list-of-articles (reverse gnus-uu-marked-article-list))
  1332.     (setq gnus-uu-marked-article-list nil))
  1333.       (if (not list-of-articles)
  1334.       (error "No list of articles"))
  1335.  
  1336.       (setq gnus-uu-binhex-article-name 
  1337.         (concat gnus-uu-work-dir 
  1338.             (read-file-name "Enter binhex file name: " 
  1339.                     gnus-newsgroup-name
  1340.                     gnus-newsgroup-name)))
  1341.       (gnus-uu-add-file gnus-uu-binhex-article-name)
  1342.       (if (gnus-uu-grab-articles list-of-articles 'gnus-uu-binhex-article t)
  1343.       (gnus-uu-save-file gnus-uu-binhex-article-name))))
  1344.   (gnus-uu-check-for-generated-files)
  1345.   (gnus-uu-summary-next-subject))
  1346.  
  1347. (defun gnus-uu-binhex-article (buffer in-state)
  1348.   (let (state start-char)
  1349.     (save-excursion
  1350.       (set-buffer buffer)
  1351.       (widen)
  1352.       (goto-char 1)
  1353.       (if (not (re-search-forward gnus-uu-binhex-begin-line nil t))
  1354.       (if (not (re-search-forward gnus-uu-binhex-body-line nil t))
  1355.           (setq state (list 'wrong-type))))
  1356.  
  1357.       (if (memq 'wrong-type state)
  1358.       ()
  1359.     (beginning-of-line)
  1360.     (setq start-char (point))
  1361.     (if (looking-at gnus-uu-binhex-begin-line)
  1362.         (progn
  1363.           (setq state (list 'begin))
  1364.           (write-region 1 1 gnus-uu-binhex-article-name))
  1365.       (setq state (list 'middle)))
  1366.     (goto-char (point-max))
  1367.     (re-search-backward (concat gnus-uu-binhex-body-line "\\|" 
  1368.                     gnus-uu-binhex-end-line) nil t)
  1369.     (if (looking-at gnus-uu-binhex-end-line)
  1370.         (setq state (if (memq 'begin state)
  1371.                 (cons 'end state)
  1372.               (list 'end))))
  1373.     (beginning-of-line)
  1374.     (forward-line 1)
  1375.     (if (file-exists-p gnus-uu-binhex-article-name)
  1376.         (append-to-file start-char (point) gnus-uu-binhex-article-name))))
  1377.     (if (memq 'begin state)
  1378.     (cons gnus-uu-binhex-article-name state)
  1379.       state)))
  1380.       
  1381.  
  1382. ;; Internal view commands
  1383.  
  1384. ; This function takes two parameters. The first is name of the file to
  1385. ; be viewed. `gnus-uu-view-file' will look for an action associated
  1386. ; with the file type of the file. If it finds an appropriate action,
  1387. ; the file will be attempted displayed.
  1388. ; The second parameter specifies if the user is to be asked whether to
  1389. ; save the file if viewing is unsuccessful. t means "do not ask."
  1390. ;
  1391. ; Note that the file given will be deleted by this function, one way
  1392. ; or another. If `gnus-uu-asynchronous' is set, it won't be deleted
  1393. ; right away, but sometime later. If the user is offered to save the
  1394. ; file, it'll be moved to wherever the user wants it.
  1395.  
  1396. ; `gnus-uu-view-file' returns t if viewing is successful.
  1397.  
  1398. (defun gnus-uu-view-file (file &optional silent)
  1399.   (let (action did-view)
  1400.     (cond 
  1401.      ((not (setq action (gnus-uu-get-action file)))
  1402.       (if (and (not silent) (not gnus-uu-use-interactive-view))
  1403.       (progn
  1404.         (message "Couldn't find any rule for file '%s'" file)
  1405.         (sleep-for 2)
  1406.         (gnus-uu-ask-to-save-file file))))
  1407.      
  1408.      ((and gnus-uu-use-interactive-view 
  1409.        (not (string= (or action "") "gnus-uu-archive")))
  1410.       (gnus-uu-enter-interactive-file (or action "") file))
  1411.  
  1412.      (gnus-uu-ask-before-view
  1413.       (if (y-or-n-p (format "Do you want to view %s? " file))
  1414.       (setq did-view (gnus-uu-call-file-action file action)))
  1415.       (message ""))
  1416.      
  1417.      ((setq did-view (gnus-uu-call-file-action file action)))
  1418.  
  1419.      ((not silent)
  1420.       (gnus-uu-ask-to-save-file file)))
  1421.  
  1422.     (if (and (file-exists-p file) 
  1423.          (not gnus-uu-use-interactive-view)
  1424.          (or 
  1425.           (not (and gnus-uu-asynchronous did-view))
  1426.           (string= (or action  "") "gnus-uu-archive")))
  1427.     (delete-file file))
  1428.  
  1429.   did-view))
  1430.  
  1431. (defun gnus-uu-call-file-action (file action)
  1432.   (prog1
  1433.       (if gnus-uu-asynchronous
  1434.       (gnus-uu-call-asynchronous file action)
  1435.     (gnus-uu-call-synchronous file action))
  1436.     (if gnus-uu-view-and-save
  1437.     (gnus-uu-ask-to-save-file file))))
  1438.  
  1439. (defun gnus-uu-ask-to-save-file (file)
  1440.   (if (y-or-n-p (format "Do you want to save the file %s? " file))
  1441.       (gnus-uu-save-file file))
  1442.   (message ""))
  1443.  
  1444. (defun gnus-uu-get-action (file-name)
  1445.   (let (action)
  1446.     (setq action 
  1447.       (gnus-uu-choose-action 
  1448.        file-name
  1449.        (append 
  1450.         (if (and gnus-uu-use-interactive-view 
  1451.              gnus-uu-user-interactive-view-rules)
  1452.         gnus-uu-user-interactive-view-rules
  1453.           gnus-uu-user-view-rules)
  1454.         (if (or gnus-uu-ignore-default-view-rules 
  1455.             (not gnus-uu-use-interactive-view))
  1456.         ()
  1457.           gnus-uu-default-interactive-view-rules-begin)
  1458.         (if gnus-uu-ignore-default-view-rules 
  1459.         nil 
  1460.           gnus-uu-default-view-rules)
  1461.         (if gnus-uu-use-interactive-view
  1462.         (append gnus-uu-user-interactive-view-rules-end
  1463.             (if gnus-uu-ignore-default-view-rules
  1464.                 ()
  1465.               gnus-uu-default-interactive-view-rules-end))
  1466.           gnus-uu-user-view-rules-end))))
  1467.     (if (and (not (string= (or action "") "gnus-uu-archive")) 
  1468.          gnus-uu-view-with-metamail)
  1469.     (if (setq action 
  1470.           (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
  1471.         (setq action (format "metamail -d -b -c \"%s\"" action))))
  1472.     action))
  1473.  
  1474. ; `gnus-uu-call-synchronous' takes two parameters: The name of the
  1475. ; file to be displayed and the command to display it with. Returns t
  1476. ; on success and nil if the file couldn't be displayed.
  1477. (defun gnus-uu-call-synchronous (file-name action)
  1478.   (let (did-view command)
  1479.     (save-excursion
  1480.       (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
  1481.       (erase-buffer)
  1482.       (setq command (gnus-uu-command action file-name))
  1483.       (message "Viewing with '%s'" command)
  1484.       (if (not (= 0 (call-process "sh" nil t nil "-c" command)))
  1485.       (progn
  1486.         (goto-char 1)
  1487.         (while (re-search-forward "\n" nil t)
  1488.           (replace-match " "))
  1489.         (message (concat "Error: " (buffer-substring 1 (point-max))))
  1490.         (sit-for 2))
  1491.     (message "")
  1492.     (setq did-view t)))
  1493.     did-view))
  1494.  
  1495. ; `gnus-uu-call-asyncronous' takes two parameters: The name of the
  1496. ; file to be displayed and the command to display it with. Since the
  1497. ; view command is executed asynchronously, it's kinda hard to decide
  1498. ; whether the command succeded or not, so this function always returns
  1499. ; t. It also adds "; rm -f file-name" to the end of the execution
  1500. ; string, so the file will be removed after viewing has ended.
  1501. (defun gnus-uu-call-asynchronous (file-name action)
  1502.   (let (command file tmp-file start)
  1503.     (while (string-match "/" file-name start)
  1504.       (setq start (1+ (match-beginning 0))))
  1505.     (setq file (substring file-name start))
  1506.     (setq tmp-file (concat gnus-uu-work-dir file))
  1507.     (if (string= tmp-file file-name)
  1508.     ()
  1509.       (rename-file file-name tmp-file t)
  1510.       (setq file-name tmp-file))
  1511.  
  1512.     (setq command (gnus-uu-command action file-name))
  1513.     (setq command (format "%s ; rm -f %s" command file-name))
  1514.     (message "Viewing with %s" command)
  1515.     (start-process "gnus-uu-view" nil "sh" "-c" command)
  1516.     t))
  1517.  
  1518. ; `gnus-uu-decode-and-strip' does all the main work. It finds out what
  1519. ; articles to grab, grabs them, strips the result and decodes. If any
  1520. ; of these operations fail, it returns nil, t otherwise.  If shar is
  1521. ; t, it will pass this on to `gnus-uu-grab-articles', which will
  1522. ; (probably) unshar the articles. If use-marked is non-nil, it won't
  1523. ; try to find articles, but use the marked list.
  1524. (defun gnus-uu-decode-and-strip (&optional shar use-marked limit)
  1525.   (let (list-of-articles)
  1526.     (save-excursion
  1527.  
  1528.       (if use-marked
  1529.       (if (not gnus-uu-marked-article-list)
  1530.           (message "No articles marked")
  1531.         (setq list-of-articles (reverse gnus-uu-marked-article-list))
  1532.         (setq gnus-uu-marked-article-list nil))
  1533.     (setq list-of-articles (gnus-uu-get-list-of-articles)))
  1534.       
  1535.       (and list-of-articles
  1536.        (gnus-uu-grab-articles 
  1537.         list-of-articles 
  1538.         (if shar 'gnus-uu-unshar-article 'gnus-uu-uustrip-article-as)
  1539.         t limit)))))
  1540.  
  1541. ; Takes a string and puts a \ in front of every special character;
  1542. ; ignores any leading "version numbers" thingies that they use in the
  1543. ; comp.binaries groups, and either replaces anything that looks like
  1544. ; "2/3" with "[0-9]+/[0-9]+" or, if it can't find something like that,
  1545. ; replaces the last two numbers with "[0-9]+". This, in my experience,
  1546. ; should get most postings of a series."
  1547. (defun gnus-uu-reginize-string (string)
  1548.   (let ((count 2)
  1549.     (vernum "v[0-9]+[a-z][0-9]+:")
  1550.     reg beg)
  1551.     (save-excursion
  1552.       (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
  1553.       (erase-buffer)
  1554.       (insert (regexp-quote string))
  1555.       (setq beg 1)
  1556.  
  1557.       (setq case-fold-search nil)
  1558.       (goto-char 1)
  1559.       (if (looking-at vernum)
  1560.       (progn
  1561.         (replace-match vernum t t)
  1562.         (setq beg (length vernum))))
  1563.  
  1564.       (goto-char beg)
  1565.       (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
  1566.       (replace-match " [0-9]+/[0-9]+")
  1567.  
  1568.     (goto-char beg)
  1569.     (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
  1570.         (replace-match "[0-9]+ of [0-9]+")
  1571.  
  1572.       (end-of-line)
  1573.       (while (and (re-search-backward "[0-9]" nil t) (> count 0))
  1574.             (while (and 
  1575.             (looking-at "[0-9]") 
  1576.             (< 1 (goto-char (1- (point))))))
  1577.             (re-search-forward "[0-9]+" nil t)
  1578.         (replace-match "[0-9]+")
  1579.         (backward-char 5)
  1580.         (setq count (1- count)))))
  1581.  
  1582.       (goto-char beg)
  1583.       (while (re-search-forward "[ \t]+" nil t)
  1584.     (replace-match "[ \t]*" t t))
  1585.  
  1586.       (buffer-substring 1 (point-max)))))
  1587.  
  1588. ; Finds all articles that matches the regular expression given.
  1589. ; Returns the resulting list. SUBJECT is the regular expression to be
  1590. ; matched. If it is nil, the current article name will be used. If
  1591. ; MARK-ARTICLES is non-nil, articles found are marked. If ONLY-UNREAD
  1592. ; is non-nil, only unread articles are chose. If DO-NOT-TRANSLATE is
  1593. ; non-nil, article names are not equialized before sorting.
  1594. (defun gnus-uu-get-list-of-articles (&optional subject mark-articles only-unread do-not-translate)
  1595.   (let (beg end reg-subject list-of-subjects list-of-numbers art-num)
  1596.     (save-excursion
  1597.       
  1598. ; If the subject is not given, this function looks at the current subject
  1599. ; and takes that.
  1600.  
  1601.       (if subject
  1602.       (setq reg-subject subject)
  1603.     (end-of-line)
  1604.     (setq end (point))
  1605.     (beginning-of-line)
  1606.     (if (not (re-search-forward "\\] " end t))
  1607.         (progn (message "No valid subject chosen") (sit-for 2))
  1608.       (setq subject (buffer-substring (point) end))
  1609.       (setq reg-subject 
  1610.         (concat "\\[.*\\] " (gnus-uu-reginize-string subject)))))
  1611.  
  1612. ;      (message reg-subject)(sleep-for 2)
  1613.       
  1614.       (if reg-subject
  1615.       (progn
  1616.  
  1617. ; Collect all subjects matching reg-subject.
  1618.  
  1619.         (let ((case-fold-search t))
  1620.           (goto-char 1)
  1621.           (while (re-search-forward reg-subject nil t)
  1622.         (beginning-of-line)
  1623.         (setq beg (point))
  1624.         (if (or (not only-unread) (looking-at " \\|-"))
  1625.             (progn
  1626.               (end-of-line)
  1627.               (setq list-of-subjects (cons 
  1628.                           (buffer-substring beg (point))
  1629.                           list-of-subjects)))
  1630.           (end-of-line))))
  1631.  
  1632. ; Expand all numbers in all the subjects: (hi9 -> hi0009, etc).
  1633.  
  1634.         (setq list-of-subjects (gnus-uu-expand-numbers 
  1635.                     list-of-subjects
  1636.                     (not do-not-translate)))
  1637.  
  1638. ; Sort the subjects.
  1639.  
  1640.         (setq list-of-subjects (sort list-of-subjects 'gnus-uu-string<))
  1641.  
  1642. ; Get the article numbers from the sorted list of subjects.
  1643.  
  1644.         (while list-of-subjects 
  1645.           (setq art-num (gnus-uu-article-number (car list-of-subjects)))
  1646.           (if mark-articles (gnus-summary-mark-as-read art-num ?#))
  1647.           (setq list-of-numbers (cons art-num list-of-numbers))
  1648.           (setq list-of-subjects (cdr list-of-subjects)))
  1649.  
  1650.         (setq list-of-numbers (nreverse list-of-numbers))))
  1651.  
  1652.       list-of-numbers)))
  1653.  
  1654. ; Takes a list of strings and "expands" all numbers in all the
  1655. ; strings.  That is, this function makes all numbers equal length by
  1656. ; prepending lots of zeroes before each number. This is to ease later
  1657. ; sorting to find out what sequence the articles are supposed to be
  1658. ; decoded in. Returns the list of expanded strings.
  1659. (defun gnus-uu-expand-numbers (string-list &optional translate)
  1660.   (let (string out-list pos num)
  1661.     (save-excursion
  1662.       (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
  1663.       (while string-list
  1664.     (erase-buffer)
  1665.     (setq string (car string-list))
  1666.     (setq string-list (cdr string-list))
  1667.     (insert string)
  1668.     (goto-char 1)
  1669.     (while (re-search-forward "[ \t]+" nil t)
  1670.       (replace-match " "))
  1671.     (goto-char 1)
  1672.     (if translate 
  1673.         (while (re-search-forward "[A-Za-z]" nil t)
  1674.           (replace-match "a" t t)))
  1675.  
  1676.     (goto-char 1)
  1677.     (if (not (search-forward "] " nil t))
  1678.         ()
  1679.       (while (re-search-forward "[0-9]+" nil t)
  1680.         (replace-match  
  1681.          (format "%06d" 
  1682.              (string-to-int (buffer-substring 
  1683.                      (match-beginning 0) (match-end 0))))))
  1684.       (setq string (buffer-substring 1 (point-max)))
  1685.       (setq out-list (cons string out-list)))))
  1686.     out-list))
  1687.  
  1688. ; Used in a sort for finding out what string is bigger, but ignoring
  1689. ; everything before the subject part.
  1690. (defun gnus-uu-string< (string1 string2) 
  1691.   (string< (substring string1 (string-match "\\] " string1))
  1692.        (substring string2 (string-match "\\] " string2))))
  1693.  
  1694.  
  1695. ;; gnus-uu-grab-article
  1696. ;
  1697. ; This is the general multi-article treatment function.  It takes a
  1698. ; list of articles to be grabbed and a function to apply to each
  1699. ; article. It puts the result in `gnus-uu-result-buffer'.
  1700. ;
  1701. ; The function to be called should take two parameters.  The first
  1702. ; parameter is the article buffer. The function should leave the
  1703. ; result, if any, in this buffer. This result is then appended on to
  1704. ; the `gnus-uu-result-buffer'. Most treatment functions will just
  1705. ; generate files...
  1706. ;
  1707. ; The second parameter is the state of the list of articles, and can
  1708. ; have four values: `first', `middle', `last' and `first-and-last'.
  1709. ;
  1710. ; The function should return a list. The list may contain the
  1711. ; following symbols:
  1712. ; `error' if an error occurred
  1713. ; `begin' if the beginning of an encoded file has been received
  1714. ;   If the list returned contains a `begin', the first element of
  1715. ;   the list *must* be a string with the file name of the decoded
  1716. ;   file.
  1717. ; `end' if the the end of an encoded file has been received
  1718. ; `middle' if the article was a body part of an encoded file
  1719. ; `wrong-type' if the article was not a part of an encoded file
  1720. ; `ok', which can be used everything is ok
  1721.  
  1722. (defvar gnus-uu-has-been-grabbed nil)
  1723.  
  1724. (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
  1725.   (let (art)
  1726.     (if (not (and gnus-uu-has-been-grabbed
  1727.           gnus-uu-unmark-articles-not-decoded))
  1728.     ()
  1729.       (if dont-unmark-last-article
  1730.       (progn
  1731.         (setq art (car gnus-uu-has-been-grabbed))
  1732.         (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed))))
  1733.       (while gnus-uu-has-been-grabbed
  1734.     (gnus-summary-mark-as-unread (car gnus-uu-has-been-grabbed) t)
  1735.     (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
  1736.       (if dont-unmark-last-article
  1737.       (setq gnus-uu-has-been-grabbed (list art))))))
  1738.  
  1739.  
  1740. ; This function takes a list of articles and a function to apply to
  1741. ; each article grabbed. The result of the function is appended on to
  1742. ; `gnus-uu-result-buffer'.
  1743. ; This function returns a list of files decoded if the grabbing and
  1744. ; the process-function has been successful and nil otherwise.
  1745. (defun gnus-uu-grab-articles (list-of-articles process-function &optional sloppy limit)
  1746.   (let ((result-buffer (get-buffer-create gnus-uu-result-buffer))
  1747.     (state 'first)
  1748.     (wrong-type t)
  1749.     has-been-begin has-been-end 
  1750.     article result-file result-files process-state)
  1751.  
  1752.     (save-excursion
  1753.       (set-buffer result-buffer)
  1754.       (erase-buffer))
  1755.     (setq gnus-uu-has-been-grabbed nil)
  1756.  
  1757.     (while (and list-of-articles 
  1758.         (not (memq 'error process-state))
  1759.         (or sloppy
  1760.             (not (memq 'end process-state))))
  1761.  
  1762.       (setq article (car list-of-articles))
  1763.       (setq list-of-articles (cdr list-of-articles))
  1764.       (setq gnus-uu-has-been-grabbed (cons article gnus-uu-has-been-grabbed))
  1765.  
  1766.       (if (> article gnus-uu-highest-article-number) 
  1767.       (setq gnus-uu-highest-article-number article))
  1768.  
  1769.       (if (eq list-of-articles ()) 
  1770.       (if (eq state 'first)
  1771.           (setq state 'first-and-last)
  1772.         (setq state 'last)))
  1773.  
  1774.       (message "Getting article %d" article)
  1775.       (if (not (= (or gnus-current-article 0) article))
  1776.       (gnus-summary-display-article article))
  1777.       (gnus-summary-mark-as-read article)
  1778.  
  1779.       (save-excursion (set-buffer gnus-article-buffer) (widen))
  1780.  
  1781.       (setq process-state (funcall process-function gnus-article-buffer state))
  1782.  
  1783. ;      (message "process-state er %s" process-state)(sleep-for 3)
  1784.  
  1785.       (if (or (memq 'begin process-state)
  1786.           (and (or (eq state 'first) (eq state 'first-and-last))
  1787.            (memq 'ok process-state)))
  1788.       (progn
  1789.         (if has-been-begin
  1790.         (if (file-exists-p result-file) (delete-file result-file)))
  1791.         (setq result-file (car process-state))
  1792.         (setq has-been-begin t)
  1793.         (setq has-been-end nil)))
  1794.  
  1795.       (if (memq 'end process-state)
  1796.       (progn
  1797.         (setq gnus-uu-has-been-grabbed nil)
  1798.         (setq result-files (cons result-file result-files))
  1799.         (setq has-been-end t)
  1800.         (setq has-been-begin nil)
  1801.         (if (and limit (= (length result-files) limit))
  1802.         (progn
  1803.           (setq list-of-articles nil)
  1804.           (setq gnus-uu-marked-article-list nil)))))
  1805.  
  1806.       (if (and (or (eq state 'last) (eq state 'first-and-last))
  1807.            (not (memq 'end process-state)))
  1808.         (if (and result-file (file-exists-p result-file))
  1809.             (delete-file result-file)))
  1810.  
  1811.       (setq result-file nil)
  1812.  
  1813.       (if (not (memq 'wrong-type process-state))
  1814.       (setq wrong-type nil)
  1815.     (if gnus-uu-unmark-articles-not-decoded
  1816.         (gnus-summary-mark-as-unread article t)))
  1817.  
  1818.       (if sloppy (setq wrong-type nil))
  1819.  
  1820.       (if (and (not has-been-begin)
  1821.            (not sloppy)
  1822.            (or (memq 'end process-state)
  1823.            (memq 'middle process-state)))
  1824.       (progn
  1825.         (setq process-state (list 'error))
  1826.         (message "No begin part at the beginning")
  1827.         (sleep-for 2))
  1828.     (setq state 'middle)))
  1829.  
  1830.     (if result-files
  1831.     ()
  1832.       (if (not has-been-begin)
  1833.       (message "Wrong type file")
  1834.     (if (memq 'error process-state)
  1835.         (setq result-files nil)
  1836.       (if (not (or (memq 'ok process-state) 
  1837.                (memq 'end process-state)))
  1838.           (progn
  1839.         (message "End of articles reached before end of file")
  1840.         (setq result-files nil))
  1841.         (gnus-uu-unmark-list-of-grabbed)))))
  1842.     (setq gnus-uu-list-of-files-decoded result-files)
  1843.     result-files))
  1844.  
  1845. (defun gnus-uu-uudecode-sentinel (process event)
  1846.   (delete-process (get-process process)))
  1847.  
  1848. ; Uudecodes a file asynchronously.
  1849. (defun gnus-uu-uustrip-article-as (process-buffer in-state)
  1850.   (let ((state (list 'ok))
  1851.     (process-connection-type nil)
  1852.     start-char pst name-beg name-end)
  1853.     (save-excursion
  1854.       (set-buffer process-buffer)
  1855.       (let ((case-fold-search nil)
  1856.         (buffer-read-only nil))
  1857.  
  1858.     (goto-char 1)
  1859.  
  1860.     (if gnus-uu-kill-carriage-return
  1861.         (progn
  1862.           (while (search-forward "\r" nil t)
  1863.         (delete-backward-char 1))
  1864.           (goto-char 1)))
  1865.  
  1866.     (if (not (re-search-forward gnus-uu-begin-string nil t))
  1867.         (if (not (re-search-forward gnus-uu-body-line nil t))
  1868.         (setq state (list 'wrong-type))))
  1869.      
  1870.     (if (memq 'wrong-type state)
  1871.         ()
  1872.       (beginning-of-line)
  1873.       (setq start-char (point))
  1874.  
  1875.       (if (looking-at gnus-uu-begin-string)
  1876.           (progn 
  1877.         (setq name-end (match-end 1))
  1878.  
  1879.         ; Replace any slashes and spaces in file names before decoding
  1880.         (goto-char (setq name-beg (match-beginning 1)))
  1881.         (while (re-search-forward "/" name-end t)
  1882.           (replace-match ","))
  1883.         (goto-char name-beg)
  1884.         (while (re-search-forward " " name-end t)
  1885.           (replace-match "_"))
  1886.  
  1887.         (setq gnus-uu-file-name (buffer-substring name-beg name-end))
  1888.         (and gnus-uu-uudecode-process
  1889.              (setq pst (process-status 
  1890.                 (or gnus-uu-uudecode-process "nevair")))
  1891.              (if (or (eq pst 'stop) (eq pst 'run))
  1892.              (progn
  1893.                (delete-process gnus-uu-uudecode-process)
  1894.                (gnus-uu-unmark-list-of-grabbed t))))
  1895.         (setq gnus-uu-uudecode-process
  1896.               (start-process 
  1897.                "*uudecode*" 
  1898.                (get-buffer-create gnus-uu-output-buffer-name)
  1899.                "sh" "-c" 
  1900.                (format "cd %s ; uudecode" gnus-uu-work-dir)))
  1901.         (set-process-sentinel 
  1902.          gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
  1903.         (setq state (list 'begin))
  1904.         (gnus-uu-add-file (concat gnus-uu-work-dir gnus-uu-file-name)))
  1905.         (setq state (list 'middle)))
  1906.     
  1907.       (goto-char (point-max))
  1908.  
  1909.       (re-search-backward 
  1910.        (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t)
  1911.       (beginning-of-line)
  1912.  
  1913.       (if (looking-at gnus-uu-end-string)
  1914.           (setq state (cons 'end state)))
  1915.       (forward-line 1)
  1916.  
  1917.       (and gnus-uu-uudecode-process
  1918.            (setq pst (process-status 
  1919.               (or gnus-uu-uudecode-process "nevair")))
  1920.            (if (or (eq pst 'run) (eq pst 'stop))
  1921.            (progn
  1922.              (if gnus-uu-correct-stripped-uucode
  1923.              (progn
  1924.                (gnus-uu-check-correct-stripped-uucode 
  1925.                 start-char (point))
  1926.                (goto-char (point-max))
  1927.                (re-search-backward 
  1928.                 (concat gnus-uu-body-line "\\|" 
  1929.                     gnus-uu-end-string) 
  1930.                 nil t)
  1931.                (forward-line 1)))
  1932.              (condition-case err
  1933.              (process-send-region gnus-uu-uudecode-process 
  1934.                           start-char (point))
  1935.                (error 
  1936.             (progn 
  1937.               (message "gnus-uu: Couldn't uudecode")
  1938.               (sleep-for 2)
  1939.               (setq state (list 'wrong-type))
  1940.               (delete-process gnus-uu-uudecode-process))))
  1941.              (if (memq 'end state)
  1942.              (accept-process-output gnus-uu-uudecode-process)))
  1943.          (setq state (list 'wrong-type))))
  1944.       (if (not gnus-uu-uudecode-process)
  1945.           (setq state (list 'wrong-type)))))
  1946.  
  1947.       (if (memq 'begin state)
  1948.       (cons (concat gnus-uu-work-dir gnus-uu-file-name) state)
  1949.     state))))
  1950.  
  1951. ; This function is used by `gnus-uu-grab-articles' to treat
  1952. ; a shared article.
  1953. (defun gnus-uu-unshar-article (process-buffer in-state)
  1954.   (let ((state (list 'ok))
  1955.     start-char)
  1956.     (save-excursion
  1957.      (set-buffer process-buffer)
  1958.      (goto-char 1)
  1959.      (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
  1960.      (setq state (list 'wrong-type))
  1961.        (beginning-of-line)
  1962.        (setq start-char (point))
  1963.        (call-process-region 
  1964.     start-char (point-max) "sh" nil 
  1965.     (get-buffer-create gnus-uu-output-buffer-name) nil 
  1966.     "-c" (concat "cd " gnus-uu-shar-directory " ; sh"))))
  1967.     state))
  1968.  
  1969. ; Returns the name of what the shar file is going to unpack.
  1970. (defun gnus-uu-find-name-in-shar ()
  1971.   (let ((oldpoint (point))
  1972.     res)
  1973.     (goto-char 1)
  1974.     (if (re-search-forward gnus-uu-shar-name-marker nil t)
  1975.     (setq res (buffer-substring (match-beginning 1) (match-end 1))))
  1976.     (goto-char oldpoint)
  1977.     res))
  1978.  
  1979. ; Returns the article number of the given subject.
  1980. (defun gnus-uu-article-number (subject)
  1981.   (let (end)
  1982.     (string-match "[0-9]+[^0-9]" subject 1)
  1983.     (setq end (match-end 0))
  1984.     (string-to-int 
  1985.      (substring subject (string-match "[0-9]" subject 1) end)))) 
  1986.           
  1987. ; `gnus-uu-choose-action' chooses what action to perform given the name
  1988. ; and `gnus-uu-file-action-list'.  Returns either nil if no action is
  1989. ; found, or the name of the command to run if such a rule is found.
  1990. (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
  1991.   (let ((action-list (copy-sequence file-action-list))
  1992.     rule action)
  1993.     (and 
  1994.      (or no-ignore 
  1995.      (and (not 
  1996.            (and gnus-uu-ignore-files-by-name
  1997.             (string-match gnus-uu-ignore-files-by-name file-name)))
  1998.           (not 
  1999.            (and gnus-uu-ignore-files-by-type
  2000.             (string-match gnus-uu-ignore-files-by-type 
  2001.                   (or (gnus-uu-choose-action 
  2002.                        file-name gnus-uu-ext-to-mime-list t) 
  2003.                       ""))))))
  2004.      (while (not (or (eq action-list ()) action))
  2005.        (setq rule (car action-list))
  2006.        (setq action-list (cdr action-list))
  2007.        (if (string-match (car rule) file-name)
  2008.        (setq action (car (cdr rule))))))
  2009.     action))
  2010.  
  2011. (defun gnus-uu-save-directory (from-dir &optional default-dir ignore-existing)
  2012.   (let (dir file-name command files file)
  2013.     (setq files (directory-files from-dir t))
  2014.     (if default-dir
  2015.     (setq dir default-dir)
  2016.       (setq dir (gnus-uu-read-directory 
  2017.          (concat "Where do you want the file" 
  2018.              (if (< 3 (length files)) "s" "") "? "))))
  2019.  
  2020.     (while files
  2021.       (setq file (car files))
  2022.       (setq files (cdr files))
  2023.       (string-match "/[^/]*$" file)
  2024.       (setq file-name (substring file (1+ (match-beginning 0))))
  2025.       (if (string-match "^\\.\\.?$" file-name)
  2026.       ()
  2027.     (if (and (not ignore-existing) (file-exists-p (concat dir file-name)))
  2028.         (setq file-name
  2029.           (read-file-name "File exists. Enter a new name: " dir 
  2030.                   (concat dir file-name) nil file-name))
  2031.       (setq file-name (concat dir file-name)))
  2032.     (rename-file file file-name t)))))
  2033.  
  2034. ; Moves the file from the tmp directory to where the user wants it.
  2035. (defun gnus-uu-save-file (from-file-name &optional default-dir ignore-existing)
  2036.   (let (dir file-name command)
  2037.     (string-match "/[^/]*$" from-file-name)
  2038.     (setq file-name (substring from-file-name (1+ (match-beginning 0))))
  2039.     (if default-dir
  2040.     (setq dir default-dir)
  2041.       (setq dir (gnus-uu-read-directory "Where do you want the file? ")))
  2042.     (if (and (not ignore-existing) (file-exists-p (concat dir file-name)))
  2043.     (setq file-name
  2044.           (read-file-name "File exist. Enter a new name: " dir 
  2045.                   (concat dir file-name) nil file-name))
  2046.       (setq file-name (concat dir file-name)))
  2047.     (rename-file from-file-name file-name t)))
  2048.     
  2049. (defun gnus-uu-read-directory (prompt &optional default)
  2050.   (let (dir ok create)
  2051.     (while (not ok)
  2052.       (setq ok t)
  2053.       (setq dir (if default default
  2054.           (read-file-name prompt gnus-uu-current-save-dir 
  2055.                   gnus-uu-current-save-dir)))
  2056.       (while (string-match "/$" dir)
  2057.     (setq dir (substring dir 0 (match-beginning 0))))
  2058.       (if (file-exists-p dir)
  2059.       (if (not (file-directory-p dir))
  2060.           (progn
  2061.         (setq ok nil)
  2062.         (message "%s is a file" dir)
  2063.         (sit-for 2)))
  2064.     (setq create ?o)
  2065.     (while (not (or (= create ?y) (= create ?n)))
  2066.       (message "%s: No such directory. Do you want to create it? (y/n)" 
  2067.            dir)
  2068.       (setq create (read-char)))
  2069.     (if (= create ?y) (make-directory dir))))
  2070.     (setq gnus-uu-current-save-dir (concat dir "/"))))
  2071.  
  2072. ; Unpacks an archive and views all the files in it. Returns t if
  2073. ; viewing one or more files is successful.
  2074. (defun gnus-uu-treat-archive (file-path)
  2075.   (let ((did-unpack t)
  2076.     action command files file file-name dir)
  2077.     (setq action (gnus-uu-choose-action 
  2078.           file-path (append gnus-uu-user-archive-rules
  2079.                     (if gnus-uu-ignore-default-archive-rules
  2080.                     nil
  2081.                       gnus-uu-default-archive-rules))))
  2082.  
  2083.     (if (not action) (error "No unpackers for the file %s" file-path))
  2084.  
  2085.     (string-match "/[^/]*$" file-path)
  2086.     (setq file-name (substring file-path (1+ (match-beginning 0))))
  2087.     (setq dir (substring file-path 0 (match-beginning 0)))
  2088.  
  2089.     (if (gnus-uu-string-in-list action gnus-uu-destructive-archivers)
  2090.     (copy-file file-path (concat file-path "~") t))
  2091.  
  2092.     (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
  2093.  
  2094.     (save-excursion
  2095.       (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
  2096.       (erase-buffer))
  2097.  
  2098.     (message "Unpacking: %s..." (gnus-uu-command action file-path))
  2099.  
  2100.     (if (= 0 (call-process "sh" nil 
  2101.                (get-buffer-create gnus-uu-output-buffer-name)
  2102.                nil "-c" command))
  2103.     (message "")
  2104.       (if (not gnus-uu-use-interactive-view)
  2105.       (progn
  2106.         (message "Error during unpacking of archive")
  2107.         (sleep-for 2)))
  2108.       (setq did-unpack nil))
  2109.  
  2110.     (if (gnus-uu-string-in-list action gnus-uu-destructive-archivers)
  2111.     (rename-file (concat file-path "~") file-path t))
  2112.  
  2113.     did-unpack))
  2114.  
  2115. ; Tries to view all the files in the given directory. Returns t if
  2116. ; viewing one or more files is successful.
  2117. (defun gnus-uu-view-directory (dir &optional dont-delete-files not-top)
  2118.   (let ((first t)
  2119.     files file did-view ignore-files)
  2120.     (setq files (directory-files dir t "[^/][^\\.][^\\.]?$"))
  2121.     (gnus-uu-add-file files)
  2122.     (setq ignore-files files)
  2123.     
  2124.     (while (gnus-uu-unpack-archives 
  2125.         files (if not-top (list ".")
  2126.             (if first () ignore-files)))
  2127.       (setq first nil)
  2128.       (gnus-uu-add-file 
  2129.        (setq files (directory-files dir t "[^/][^\\.][^\\.]?$"))))
  2130.  
  2131.     (gnus-uu-add-file (directory-files dir t "[^/][^\\.][^\\.]?$"))
  2132.       
  2133.     (while files
  2134.       (setq file (car files))
  2135.       (setq files (cdr files))
  2136.       (if (not (string= (or (gnus-uu-get-action file) "") "gnus-uu-archive"))
  2137.       (progn
  2138.         (set-file-modes file 448)
  2139.         (if (file-directory-p file)
  2140.         (setq did-view (or (gnus-uu-view-directory file 
  2141.                                dont-delete-files 
  2142.                                t) 
  2143.                    did-view))
  2144.           (setq did-view (or (gnus-uu-view-file file t) did-view)))))
  2145.       (if (and (not dont-delete-files) (not gnus-uu-asynchronous) 
  2146.            (file-exists-p file))
  2147.       (delete-file file)))
  2148.  
  2149.     (if (and (not gnus-uu-asynchronous) (not dont-delete-files))
  2150.     (if (string-match "/$" dir)
  2151.         (delete-directory (substring dir 0 (match-beginning 0)))
  2152.       (delete-directory dir)))
  2153.     did-view))
  2154.  
  2155. (defun gnus-uu-unpack-archives (files &optional ignore)
  2156.   (let (path did-unpack)
  2157.     (while files
  2158.       (setq path (car files))
  2159.       (setq files (cdr files))
  2160.       (if (not (gnus-uu-string-in-list path ignore))
  2161.       (if (string= (or (gnus-uu-get-action 
  2162.                 (gnus-uu-name-from-path path)) "") 
  2163.                "gnus-uu-archive")
  2164.           (progn
  2165.         (if (and (not (setq did-unpack (gnus-uu-treat-archive path)))
  2166.              gnus-uu-use-interactive-view)
  2167.             (gnus-uu-enter-interactive-file 
  2168.              "# error during unpacking of" path))
  2169.         (if ignore (delete-file path))))))
  2170.     did-unpack))
  2171.  
  2172.  
  2173. ;; Manual marking
  2174.  
  2175. (defun gnus-uu-enter-mark-in-list ()
  2176.   (let (article    beg)
  2177.     (save-excursion
  2178.       (beginning-of-line)
  2179.       (setq beg (point))
  2180.       (end-of-line)
  2181.       (setq article (gnus-uu-article-number 
  2182.              (buffer-substring beg (point))))
  2183.       (message "Adding article %d to list" article)
  2184.       (setq gnus-uu-marked-article-list 
  2185.         (cons article gnus-uu-marked-article-list))))) 
  2186.  
  2187. (defun gnus-uu-mark-article (&optional dont-move)
  2188.   "Marks the current article to be decoded later."
  2189.   (interactive)
  2190.   (gnus-uu-enter-mark-in-list)
  2191.   (gnus-summary-mark-as-read nil ?#)
  2192.   (gnus-summary-next-subject 1 nil))
  2193.  
  2194. (defun gnus-uu-unmark-article ()
  2195.   "Unmarks the current article."
  2196.   (interactive)
  2197.   (let ((in (copy-sequence gnus-uu-marked-article-list))
  2198.     out article beg found
  2199.     (old-point (point)))
  2200.     (beginning-of-line)
  2201.       (setq beg (point))
  2202.       (end-of-line)
  2203.       (setq article (gnus-uu-article-number (buffer-substring beg (point))))
  2204.       (message "Removing article %d" article)
  2205.       (while in 
  2206.     (if (not (= (car in) article))
  2207.         (setq out (cons (car in) out))
  2208.       (setq found t)
  2209.       (message "Removing article %d" article))
  2210.     (setq in (cdr in)))
  2211.       (if (not found) (message "Not a marked article."))
  2212.       (setq gnus-uu-marked-article-list (reverse out))
  2213.       (gnus-summary-mark-as-unread nil t)
  2214.       (gnus-summary-next-subject 1 nil)))
  2215.  
  2216. (defun gnus-uu-unmark-all-articles ()
  2217.   "Removes the mark from all articles marked for decoding."
  2218.   (interactive)
  2219.   (while gnus-uu-marked-article-list
  2220.     (gnus-summary-goto-subject (car gnus-uu-marked-article-list))
  2221.     (gnus-summary-mark-as-unread nil t)
  2222.     (setq gnus-uu-marked-article-list (cdr gnus-uu-marked-article-list))))
  2223.  
  2224. (defun gnus-uu-mark-by-regexp ()
  2225.   "Asks for a regular expression and marks all articles that match."
  2226.   (interactive)
  2227.   (let (exp)
  2228.     (setq exp (read-from-minibuffer "Mark (regexp): "))
  2229.     (setq gnus-uu-marked-article-list 
  2230.       (append gnus-uu-marked-article-list
  2231.           (reverse (gnus-uu-get-list-of-articles exp t))))
  2232.     (message "")))
  2233.       
  2234. (defun gnus-uu-mark-thread ()
  2235.   "Marks all articles downwards in this thread."
  2236.   (interactive)
  2237.   (beginning-of-line)
  2238.   (let (level)
  2239.     (if (not (search-forward ":" nil t))
  2240.     ()
  2241.       (setq level (current-column))
  2242.       (gnus-uu-enter-mark-in-list)
  2243.       (gnus-summary-mark-as-read nil ?#)
  2244.       (gnus-summary-search-forward)
  2245.       (while (< level (current-column))
  2246.     (gnus-uu-enter-mark-in-list)
  2247.     (gnus-summary-mark-as-read nil ?#)
  2248.     (gnus-summary-search-forward))
  2249.       (gnus-summary-search-backward))))
  2250.  
  2251.  
  2252. ;; Various stuff
  2253.  
  2254. (defun gnus-uu-string-in-list (string list)
  2255.   (while (and list
  2256.           (not (string= (car list) string))
  2257.           (setq list (cdr list))))
  2258.   list)
  2259.  
  2260. (defun gnus-uu-name-from-path (path)
  2261.   (string-match "/[^/]*$" path)
  2262.   (substring path (1+ (match-beginning 0))))
  2263.  
  2264. (defun gnus-uu-directory-files (dir)
  2265.   (let (files out file)
  2266.     (setq files (directory-files dir t))
  2267.     (while files
  2268.       (setq file (car files))
  2269.       (setq files (cdr files))
  2270.       (if (not (string-match "/\\.\\.?$" file))
  2271.       (setq out (cons file out))))
  2272.     (setq out (reverse out))
  2273.     out))
  2274.  
  2275. (defun gnus-uu-check-correct-stripped-uucode (start end)
  2276.   (let (found beg length short)
  2277.     (if (not gnus-uu-correct-stripped-uucode)
  2278.     ()
  2279.       (goto-char start)
  2280.  
  2281.       (if (re-search-forward " \\|`" end t)
  2282.       (progn
  2283.         (goto-char start)
  2284.         (while (not (eobp))
  2285.           (progn
  2286.         (if (looking-at "\n") (replace-match ""))
  2287.         (forward-line 1))))
  2288.         
  2289.     (while (not (eobp))
  2290.       (if (looking-at (concat gnus-uu-begin-string "\\|" 
  2291.                   gnus-uu-end-string))
  2292.           ()
  2293.         (if (not found)
  2294.         (progn
  2295.           (beginning-of-line)
  2296.           (setq beg (point))
  2297.           (end-of-line)
  2298.           (setq length (- (point) beg))))
  2299.         (setq found t)
  2300.         (beginning-of-line)
  2301.         (setq beg (point))
  2302.         (end-of-line)
  2303.         (if (not (= length (- (point) beg)))
  2304.         (insert (make-string (- length (- (point) beg)) ? ))))
  2305.       (forward-line 1))))))
  2306.  
  2307. (defun gnus-uu-initialize ()
  2308.   (setq gnus-uu-highest-article-number 1)
  2309.   (gnus-uu-check-for-generated-files)
  2310.   (setq gnus-uu-tmp-dir (expand-file-name gnus-uu-tmp-dir))
  2311.   (if (string-match "[^/]$" gnus-uu-tmp-dir) 
  2312.       (setq gnus-uu-tmp-dir (concat gnus-uu-tmp-dir "/")))
  2313.   (if (not (file-directory-p gnus-uu-tmp-dir))
  2314.       (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
  2315.     (if (not (file-writable-p gnus-uu-tmp-dir))
  2316.     (error "Temp directory %s can't be written to" gnus-uu-tmp-dir)))
  2317.   (setq gnus-uu-work-dir 
  2318.     (concat gnus-uu-tmp-dir (make-temp-name "gnus")))
  2319.   (gnus-uu-add-file gnus-uu-work-dir)
  2320.   (if (not (file-directory-p gnus-uu-work-dir)) 
  2321.       (make-directory gnus-uu-work-dir))
  2322.   (setq gnus-uu-work-dir (concat gnus-uu-work-dir "/"))
  2323.   (setq gnus-uu-interactive-file-list nil))
  2324.  
  2325. ; Kills the temporary uu buffers, kills any processes, etc.
  2326. (defun gnus-uu-clean-up ()
  2327.   (let (buf pst)
  2328.     (and gnus-uu-uudecode-process
  2329.      (setq pst (process-status (or gnus-uu-uudecode-process "nevair")))
  2330.      (if (or (eq pst 'stop) (eq pst 'run))
  2331.          (delete-process gnus-uu-uudecode-process)))
  2332.     (and (not gnus-uu-asynchronous) 
  2333.      (setq buf (get-buffer gnus-uu-output-buffer-name))
  2334.      (kill-buffer buf))
  2335.     (and (setq buf (get-buffer gnus-uu-result-buffer))
  2336.      (kill-buffer buf))))
  2337.  
  2338. ; `gnus-uu-check-for-generated-files' deletes any generated files that
  2339. ; hasn't been deleted, if, for instance, the user terminated decoding
  2340. ; with `C-g'.
  2341. (defun gnus-uu-check-for-generated-files ()
  2342.   (let (file dirs)
  2343.     (while gnus-uu-generated-file-list
  2344.       (setq file (car gnus-uu-generated-file-list))
  2345.       (setq gnus-uu-generated-file-list (cdr gnus-uu-generated-file-list))
  2346.       (if (not (string-match "/\\.[\\.]?$" file))
  2347.       (progn
  2348.         (if (file-directory-p file)
  2349.         (setq dirs (cons file dirs))
  2350.           (if (file-exists-p file)
  2351.           (delete-file file))))))
  2352.     (setq dirs (nreverse dirs))
  2353.     (while dirs
  2354.       (setq file (car dirs))
  2355.       (setq dirs (cdr dirs))
  2356.       (if (file-directory-p file)
  2357.       (if (string-match "/$" file)
  2358.           (delete-directory (substring file 0 (match-beginning 0)))
  2359.         (delete-directory file))))))
  2360.  
  2361. ; Add a file (or a list of files) to be checked (and deleted if it/they
  2362. ; still exists upon exiting the newsgroup).
  2363. (defun gnus-uu-add-file (file)
  2364.   (if (stringp file)
  2365.       (setq gnus-uu-generated-file-list 
  2366.         (cons file gnus-uu-generated-file-list))
  2367.     (setq gnus-uu-generated-file-list 
  2368.       (append file gnus-uu-generated-file-list))))
  2369.  
  2370. ; Go to the next unread subject. If there is no further unread
  2371. ; subjects, go to the last subject in the buffer.
  2372. (defun gnus-uu-summary-next-subject ()
  2373.   (let (opi)
  2374.     (if (not (gnus-summary-search-forward t))
  2375.     (progn
  2376.       (goto-char 1)
  2377.       (sit-for 0)
  2378.       (gnus-summary-goto-subject gnus-uu-highest-article-number)))
  2379.  
  2380.     ; You may well find all this a bit puzzling - so do I, but I seem
  2381.     ; to have to do something like this to move to the next unread article,
  2382.     ; as `sit-for' seems to do some rather strange things here. Might
  2383.     ; be a bug in my head, probably.
  2384.     (setq opi (point))
  2385.     (sit-for 0)
  2386.     (goto-char opi)
  2387.     (gnus-summary-recenter)))
  2388.  
  2389. ; Inputs an action and a file and returns a full command, putting
  2390. ; ticks round the file name and escaping any ticks in the file name.
  2391. (defun gnus-uu-command (action file)
  2392.   (let ((ofile ""))
  2393.     (while (string-match "`\\|\"\\|\\$\\|\\\\" file)
  2394.       (progn
  2395.     (setq ofile
  2396.           (concat ofile (substring file 0 (match-beginning 0)) "\\"
  2397.               (substring file (match-beginning 0) (match-end 0))))
  2398.     (setq file (substring file (1+ (match-beginning 0))))))
  2399.     (setq ofile (concat "\"" ofile file "\""))
  2400.     (if (string-match "%s" action)
  2401.     (format action ofile)
  2402.       (concat action " " ofile))))
  2403.  
  2404.  
  2405. ;; Initializing
  2406. (add-hook 'gnus-exit-group-hook
  2407.       '(lambda ()
  2408.      (gnus-uu-clean-up)
  2409.      (setq gnus-uu-marked-article-list nil)
  2410.      (gnus-uu-check-for-generated-files)))
  2411.  
  2412.  
  2413. ;; Interactive exec mode
  2414.  
  2415. (defvar gnus-uu-output-window nil)
  2416. (defvar gnus-uu-mode-hook nil)
  2417.  
  2418. (defvar gnus-uu-mode-map nil)
  2419. (if gnus-uu-mode-map
  2420.     ()
  2421.   (setq gnus-uu-mode-map (make-sparse-keymap))
  2422.   (define-key gnus-uu-mode-map "\C-c\C-x" 'gnus-uu-interactive-execute)
  2423.   (define-key gnus-uu-mode-map "\C-c\C-v" 'gnus-uu-interactive-execute)
  2424.   (define-key gnus-uu-mode-map "\C-m" 'gnus-uu-interactive-execute)
  2425.   (define-key gnus-uu-mode-map "\C-c\C-c" 'gnus-uu-interactive-end)
  2426.   (define-key gnus-uu-mode-map "\C-cs" 
  2427.     'gnus-uu-interactive-save-current-file)
  2428.   (define-key gnus-uu-mode-map "\C-c\C-s"
  2429.     'gnus-uu-interactive-save-current-file-silent)
  2430.   (define-key gnus-uu-mode-map "\C-c\C-w" 'gnus-uu-interactive-save-all-files)
  2431.   (define-key gnus-uu-mode-map "\C-c\C-o" 'gnus-uu-interactive-save-original-file)
  2432.   (define-key gnus-uu-mode-map "\C-c\C-r" 'gnus-uu-interactive-rescan-directory)
  2433.   (define-key gnus-uu-mode-map "\C-cr" 'gnus-uu-interactive-scan-directory)
  2434.   )
  2435.  
  2436. (defun gnus-uu-interactive-set-up-windows ()
  2437.   (let (int-buf out-buf)
  2438.     (set-buffer 
  2439.      (setq int-buf (get-buffer-create gnus-uu-interactive-buffer-name)))
  2440.     (if (not (get-buffer-window int-buf))
  2441.     (switch-to-buffer-other-window int-buf))
  2442.     (pop-to-buffer int-buf)
  2443.     (setq out-buf (get-buffer-create gnus-uu-output-buffer-name))
  2444.     (if (not (get-buffer-window out-buf))
  2445.     (progn
  2446.       (setq gnus-uu-output-window 
  2447.         (split-window nil (- (window-height) 
  2448.                      gnus-uu-output-window-height)))
  2449.       (set-window-buffer gnus-uu-output-window out-buf)))))
  2450.  
  2451. (defun gnus-uu-do-interactive (&optional dont-do-windows)
  2452.   (if (not gnus-uu-interactive-file-list) 
  2453.       (gnus-uu-enter-interactive-file "#" ""))
  2454.   (if (not dont-do-windows) (gnus-uu-interactive-set-up-windows))
  2455.   (save-excursion 
  2456.     (set-buffer (get-buffer-create gnus-uu-output-buffer-name)) 
  2457.     (erase-buffer))
  2458.   (set-buffer (get-buffer-create gnus-uu-interactive-buffer-name))
  2459.   (goto-char 1)
  2460.   (forward-line 3)
  2461.   (run-hooks 'gnus-uu-mode-hook))
  2462.  
  2463. (defun gnus-uu-enter-interactive-file (action file)
  2464.   (let (command)
  2465.     (save-excursion
  2466.       (set-buffer (get-buffer-create gnus-uu-interactive-buffer-name))
  2467.       (if (not gnus-uu-interactive-file-list)
  2468.       (progn
  2469.         (erase-buffer)
  2470.         (gnus-uu-mode)
  2471.         (insert 
  2472.          "# Press return to execute a command.
  2473. # Press `C-c C-c' to exit interactive view.
  2474.  
  2475. ")))   
  2476.       (setq gnus-uu-interactive-file-list
  2477.         (cons file gnus-uu-interactive-file-list))
  2478. ;      (if (string-match (concat "^" gnus-uu-work-dir) file)
  2479. ;      (setq file (substring file (match-end 0))))
  2480.       (setq command (gnus-uu-command action file))
  2481.       (goto-char (point-max))
  2482.       (insert (format "%s\n" command)))))
  2483.  
  2484. (defun gnus-uu-interactive-execute ()
  2485.   "Executes the command on the current line in interactive mode."
  2486.   (interactive)
  2487.   (let (beg out-buf command)
  2488.     (beginning-of-line)
  2489.     (setq beg (point))
  2490.     (end-of-line)
  2491.     (setq command (buffer-substring beg (point)))
  2492.     (setq out-buf (get-buffer-create gnus-uu-output-buffer-name))
  2493.     (save-excursion
  2494.       (set-buffer out-buf)
  2495.       (erase-buffer)
  2496.       (insert (format "$ %s \n\n" command)))
  2497.     (setq command (format "cd %s ; %s" gnus-uu-work-dir command))
  2498.     (message "Executing...")
  2499.     (if gnus-uu-asynchronous
  2500.     (start-process "gnus-uu-view" out-buf "sh" "-c" command)
  2501.       (call-process "sh" nil out-buf nil "-c" command)
  2502.       (message ""))
  2503.     (end-of-line)
  2504.     (if (= (forward-line 1) 1)
  2505.     (progn
  2506.       (end-of-line)
  2507.       (insert "\n")))
  2508.     (beginning-of-line)))
  2509.  
  2510. (defun gnus-uu-interactive-end ()
  2511.   "This function exits interactive view mode and returns to summary mode."
  2512.   (interactive)
  2513.   (let (buf)
  2514.     (delete-window gnus-uu-output-window)
  2515.     (gnus-uu-clean-up)
  2516.     (if (not gnus-uu-asynchronous) (gnus-uu-check-for-generated-files))
  2517.     (setq buf (get-buffer gnus-uu-interactive-buffer-name))
  2518.     (if gnus-article-buffer (switch-to-buffer gnus-article-buffer))
  2519.     (if buf (kill-buffer buf))
  2520.     (pop-to-buffer gnus-summary-buffer)))
  2521.  
  2522.  
  2523. (defun gnus-uu-interactive-scan-directory (dir)
  2524.   "Read any directory and view the files.
  2525. When used in interactive mode, the files and commands will be displayed,
  2526. as usual, in the interactive mode buffer."
  2527.   (interactive "DDirectory: ")
  2528.   (setq gnus-uu-interactive-file-list nil)
  2529.   (gnus-uu-view-directory dir gnus-uu-use-interactive-view)
  2530.   (gnus-uu-do-interactive t))
  2531.   
  2532. (defun gnus-uu-interactive-rescan-directory ()
  2533.   "Reread the directory and view the files.
  2534. When used in interactive mode, the files and commands will be displayed,
  2535. as usual, in the interactive mode buffer."
  2536.   (interactive)
  2537.   (gnus-uu-interactive-scan-directory gnus-uu-work-dir))
  2538.  
  2539. (defun gnus-uu-interactive-save-original-file ()
  2540.   "Saves the file from whence the file on the current line came from."
  2541.   (interactive)
  2542.   (let ((files gnus-uu-list-of-files-decoded)
  2543.     (filestr "")
  2544.     file did dir)
  2545.     (while files
  2546.       (setq file (car files))
  2547.       (setq files (cdr files))
  2548.       (if (file-exists-p file)
  2549.       (progn
  2550.         (if (not did)
  2551.         (progn
  2552.           (setq dir (gnus-uu-read-directory 
  2553.                  (format "Where do you want the file%s? " 
  2554.                      (if (> (length files) 1) "s" ""))))
  2555.           (setq did t)))
  2556.         (setq filestr (concat filestr (gnus-uu-name-from-path file) " "))
  2557.         (gnus-uu-save-file file dir t)))
  2558.       (if did 
  2559.       (message "Saved %s" filestr)
  2560.     (message "Already saved.")))))
  2561.  
  2562. (defun gnus-uu-interactive-save-current-file-silent ()
  2563.   "Saves the file referred to on the current line in the current directory."
  2564.   (interactive)
  2565.   (gnus-uu-interactive-save-current-file t))
  2566.  
  2567. (defun gnus-uu-interactive-save-current-file (&optional dont-ask silent)
  2568.   "Saves the file referred to on the current line."
  2569.   (interactive)
  2570.   (let (files beg line file)
  2571.     (setq files (copy-sequence gnus-uu-interactive-file-list))
  2572.     (beginning-of-line)
  2573.     (setq beg (point))
  2574.     (end-of-line)
  2575.     (setq line (buffer-substring beg (point)))
  2576.     (while (and files
  2577.         (not (string-match 
  2578.               (concat "" (regexp-quote (setq file (car files))) "")
  2579.               line)))
  2580.       (setq files (cdr files)))
  2581.     (beginning-of-line)
  2582.     (forward-line 1)
  2583.     (if (not files)
  2584.     (if (not silent)
  2585.         (progn (message "Could not find file") (sit-for 2)))
  2586.       (gnus-uu-save-file file (if dont-ask gnus-uu-current-save-dir nil) silent)
  2587.       (delete-region beg (point)))))
  2588.  
  2589. (defun gnus-uu-interactive-save-all-files ()
  2590.   "Saves all files referred to in the interactive buffer."
  2591.   (interactive)
  2592.   (let (dir)
  2593.     (goto-char 1)
  2594.     (setq dir (gnus-uu-read-directory "Where do you want the files? "))
  2595.     (while (not (eobp))
  2596.       (gnus-uu-interactive-save-current-file t t))))
  2597.  
  2598. (defun gnus-uu-mode ()
  2599.   "Major mode for editing view commands in gnus-uu.
  2600.  
  2601. Commands:
  2602. \\<gnus-uu-mode-map>Return, C-c C-v, C-c C-x        Execute the current command
  2603. \\[gnus-uu-interactive-end]\tEnd interactive mode
  2604. \\[gnus-uu-interactive-save-current-file]\tSave the current file
  2605. \\[gnus-uu-interactive-save-current-file-silent]\tSave the current file without asking 
  2606. \twhere to put it
  2607. \\[gnus-uu-interactive-save-all-files]\tSave all files
  2608. \\[gnus-uu-interactive-save-original-file]\tSave the original file: If the files
  2609. \toriginated in an archive, the archive 
  2610. \tfile is saved.
  2611. \\[gnus-uu-interactive-rescan-directory]\tRescan the directory
  2612. \\[gnus-uu-interactive-scan-directory]\tScan any directory
  2613. "
  2614.   (interactive)
  2615.   (kill-all-local-variables)
  2616.   (use-local-map gnus-uu-mode-map)   
  2617.   (setq mode-name "gnus-uu")         
  2618.   (setq major-mode 'gnus-uu-mode)    
  2619. )
  2620.  
  2621.   (define-key gnus-uu-mode-map "\C-c\C-x" 'gnus-uu-interactive-execute)
  2622.   (define-key gnus-uu-mode-map "\C-c\C-v" 'gnus-uu-interactive-execute)
  2623.   (define-key gnus-uu-mode-map "\C-m" 'gnus-uu-interactive-execute)
  2624.   (define-key gnus-uu-mode-map "\C-c\C-c" 'gnus-uu-interactive-end)
  2625.   (define-key gnus-uu-mode-map "\C-cs" 
  2626.     'gnus-uu-interactive-save-current-file)
  2627.   (define-key gnus-uu-mode-map "\C-c\C-s"
  2628.     'gnus-uu-interactive-save-current-file-silent)
  2629.   (define-key gnus-uu-mode-map "\C-c\C-a" 'gnus-uu-interactive-save-all-files)
  2630.   (define-key gnus-uu-mode-map "\C-c\C-o" 'gnus-uu-interactive-save-original-file)
  2631.  
  2632.  
  2633. ;; Major mode for posting encoded articles.
  2634.  
  2635. (require 'sendmail)
  2636. (require 'rnews)
  2637.  
  2638. ; Any function that is to be used as and encoding method will take two
  2639. ; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
  2640. ; and "spiral.jpg", respectively.) The function should return nil if
  2641. ; the encoding wasn't successful.
  2642. (defvar gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
  2643.   "Function used for encoding binary files.
  2644. There are three functions supplied with gnus-uu for encoding files:
  2645. `gnus-uu-post-encode-uuencode', which does straight uuencoding;
  2646. `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME 
  2647. headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with 
  2648. uuencode and adds MIME headers.")
  2649.  
  2650. (defvar gnus-uu-post-include-before-composing nil
  2651.   "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
  2652. If this variable is t, you can either include an encoded file with
  2653. \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article.")
  2654.  
  2655. (defvar gnus-uu-post-length 990
  2656.   "Maximum length of an article.
  2657. The encoded file will be split into how many articles it takes to
  2658. post the entire file.")
  2659.  
  2660. (defvar gnus-uu-post-threaded nil
  2661.   "Non-nil means that gnus-uu will post the encoded file in a thread.
  2662. This may not be smart, as no other decoder I have seen are able to
  2663. follow threads when collecting uuencoded articles. (Well, I have seen
  2664. one package that does that - gnus-uu, but somehow, I don't think that 
  2665. counts...) Default is nil.")
  2666.  
  2667. (defvar gnus-uu-post-separate-description t
  2668.   "Non-nil means that the description will be posted in a separate article.
  2669. The first article will typically be numbered (0/x). If this variable
  2670. is nil, the description the user enters will be included at the 
  2671. beginning of the first article, which will be numbered (1/x). Default 
  2672. is t.")
  2673.  
  2674. (defconst gnus-uu-post-binary-separator "--binary follows this line--")
  2675. (defvar gnus-uu-post-message-id nil)
  2676. (defvar gnus-uu-post-inserted-file-name nil)
  2677. (defvar gnus-uu-winconf-post-news nil)
  2678.  
  2679. ; The following map and mode was taken from rnewspost.el and edited
  2680. ; somewhat.
  2681. (defvar gnus-uu-post-reply-mode-map () "Mode map used by gnus-uu-post-reply.")
  2682. (or gnus-uu-post-reply-mode-map
  2683.     (progn
  2684.       (setq gnus-uu-post-reply-mode-map (make-keymap))
  2685.       (define-key gnus-uu-post-reply-mode-map "\C-c?" 'describe-mode)
  2686.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-d" 
  2687.     'news-reply-distribution)
  2688.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-k" 
  2689.     'news-reply-keywords)
  2690.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-n" 
  2691.     'news-reply-newsgroups)
  2692.       
  2693.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-f" 
  2694.     'news-reply-followup-to)
  2695.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-s" 'mail-subject)
  2696.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-a" 
  2697.     'gnus-uu-post-reply-summary)
  2698.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-r" 
  2699.     'news-caesar-buffer-body)
  2700.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-w" 'news-reply-signature)
  2701.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-y" 
  2702.     'news-reply-yank-original)
  2703.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-q" 
  2704.     'mail-fill-yanked-message)
  2705.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-c" 
  2706.     'gnus-uu-post-news-inews)
  2707.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-s" 
  2708.     'gnus-uu-post-news-inews)
  2709.       (define-key gnus-uu-post-reply-mode-map "\C-c\C-i" 
  2710.     'gnus-uu-post-insert-binary-in-article)
  2711.       ))
  2712.  
  2713. ; This mode was taken from rnewspost.el and modified slightly.
  2714. (defun gnus-uu-post-reply-mode ()
  2715.   "Major mode for editing binary news to be posted on USENET.
  2716. First-time posters are asked to please read the articles in newsgroup:
  2717.                                                      news.announce.newusers .
  2718.  
  2719. Like news-reply-mode, which is like Text Mode, but with these
  2720. additional commands:
  2721.  
  2722. \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-news-inews]  post the message.
  2723. C-c C-f     move to a header field (and create it if there isn't):
  2724.      C-c C-f C-n  move to Newsgroups:    C-c C-f C-s  move to Subj:
  2725.      C-c C-f C-f  move to Followup-To:      C-c C-f C-k  move to Keywords:
  2726.      C-c C-f C-d  move to Distribution:    C-c C-f C-a  move to Summary:
  2727. C-c C-y  news-reply-yank-original (insert current message, in NEWS).
  2728. C-c C-q  mail-fill-yanked-message (fill what was yanked).
  2729. C-c C-r  caesar rotate all letters by 13 places in the article's body (rot13).
  2730. \\[gnus-uu-post-insert-binary-in-article]  encode and include a file in this article.
  2731.  
  2732. This mode is almost identical to news-reply-mode, but has some
  2733. additional commands for treating encoded binary articles. In
  2734. particular, \\[gnus-uu-post-news-inews] will ask for a file to include, if
  2735. one hasn't been included already. It will post, first, the message
  2736. composed, and then it will post as many additional articles it takes
  2737. to post the entire encoded files.
  2738.  
  2739.    Relevant Variables
  2740.  
  2741.    `gnus-uu-post-encode-method' 
  2742.    There are three functions supplied with gnus-uu for encoding files:
  2743.    `gnus-uu-post-encode-uuencode', which does straight uuencoding;
  2744.    `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME 
  2745.    headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with 
  2746.    uuencode and adds MIME headers.
  2747.  
  2748.    `gnus-uu-post-include-before-composing'
  2749.    Non-nil means that gnus-uu will ask for a file to encode before you
  2750.    compose the article.  If this variable is t, you can either include
  2751.    an encoded file with `C-c C-i' or have one included for you when you 
  2752.    post the article.
  2753.  
  2754.    `gnus-uu-post-length'
  2755.    Maximum length of an article. The encoded file will be split into how 
  2756.    many articles it takes to post the entire file.
  2757.  
  2758.    `gnus-uu-post-separate-description'
  2759.    Non-nil means that the description will be posted in a separate 
  2760.    article. The first article will typically be numbered (0/x). If 
  2761.    this variable is nil, the description the user enters will be 
  2762.    included at the beginning of the first article, which will be 
  2763.    numbered (1/x). Default is t.
  2764.  
  2765.    `gnus-uu-post-threaded'
  2766.    Non-nil means that gnus-uu will post the encoded file in a thread.
  2767.    This may not be smart, as no other decoder I have seen are able to
  2768.    follow threads when collecting uuencoded articles. (Well, I have seen
  2769.    one package that does that - gnus-uu, but somehow, I don't think that 
  2770.    counts...) Default is nil.
  2771. "
  2772.   (interactive)
  2773.   ;; require...
  2774.   (or (fboundp 'mail-setup) (load "sendmail"))
  2775.   (kill-all-local-variables)
  2776.   (make-local-variable 'mail-reply-buffer)
  2777.   (setq mail-reply-buffer nil)
  2778.   (set-syntax-table text-mode-syntax-table)
  2779.   (use-local-map gnus-uu-post-reply-mode-map)
  2780.   (setq local-abbrev-table text-mode-abbrev-table)
  2781.   (setq major-mode 'gnus-uu-post-reply-mode)
  2782.   (setq mode-name "Gnus UU News")
  2783.   (make-local-variable 'paragraph-separate)
  2784.   (make-local-variable 'paragraph-start)
  2785.   (setq paragraph-start (concat "^" mail-header-separator "$\\|"
  2786.                 paragraph-start))
  2787.   (setq paragraph-separate (concat "^" mail-header-separator "$\\|"
  2788.                    paragraph-separate))
  2789.   (run-hooks 'text-mode-hook 'gnus-uu-post-reply-mode-hook))
  2790.  
  2791. (defun gnus-uu-post-news ()
  2792.   "Compose an article and post an encoded file."
  2793.   (interactive)
  2794.   (setq gnus-uu-post-inserted-file-name nil)
  2795.   (setq gnus-uu-winconf-post-news (current-window-configuration))
  2796.   (let (news-reply-mode)
  2797.     (fset 'news-reply-mode 'gnus-uu-post-reply-mode)
  2798.     (gnus-summary-post-news)
  2799.     (if gnus-uu-post-include-before-composing
  2800.     (save-excursion (setq gnus-uu-post-inserted-file-name 
  2801.                   (gnus-uu-post-insert-binary))))))
  2802.  
  2803. (defun gnus-uu-post-insert-binary-in-article ()
  2804.   "Inserts an encoded file in the buffer.
  2805. The user will be asked for a file name."
  2806.   (interactive)
  2807.   (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
  2808.       (error "Not in post-news buffer"))
  2809.   (save-excursion 
  2810.     (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
  2811.  
  2812. ; Encodes with uuencode and substitutes all spaces with backticks.
  2813. (defun gnus-uu-post-encode-uuencode (path file-name)
  2814.   (if (gnus-uu-post-encode-file "uuencode" path file-name)
  2815.       (progn
  2816.     (goto-char 1)
  2817.     (forward-line 1)
  2818.     (while (re-search-forward " " nil t)
  2819.       (replace-match "`"))
  2820.     t)))
  2821.  
  2822. ; Encodes with uuencode and adds MIME headers.
  2823. (defun gnus-uu-post-encode-mime-uuencode (path file-name)
  2824.   (if (gnus-uu-post-encode-uuencode path file-name)
  2825.       (progn
  2826.     (gnus-uu-post-make-mime file-name "x-uue")
  2827.     t)))
  2828.  
  2829. ; Encodes with base64 and adds MIME headers
  2830. (defun gnus-uu-post-encode-mime (path file-name)
  2831.   (if (gnus-uu-post-encode-file "mmencode" path file-name)
  2832.       (progn
  2833.     (gnus-uu-post-make-mime file-name "base64")
  2834.     t)))
  2835.  
  2836. ; Adds MIME headers.
  2837. (defun gnus-uu-post-make-mime (file-name encoding)
  2838.   (goto-char 1)
  2839.   (insert (format "Content-Type: %s; name=\"%s\"\n" 
  2840.           (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list) 
  2841.           file-name))
  2842.   (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
  2843.   (save-restriction
  2844.     (set-buffer gnus-post-news-buffer)
  2845.     (goto-char 1)
  2846.     (re-search-forward mail-header-separator)
  2847.     (beginning-of-line)
  2848.     (forward-line -1)
  2849.     (narrow-to-region 1 (point))
  2850.     (or (mail-fetch-field "mime-version")
  2851.     (progn
  2852.       (widen)
  2853.       (insert "MIME-Version: 1.0\n")))
  2854.     (widen)))
  2855.  
  2856. ; Encodes a file PATH with COMMAND, leaving the result in the
  2857. ; current buffer.
  2858. (defun gnus-uu-post-encode-file (command path file-name)
  2859.   (= 0 (call-process "sh" nil t nil "-c" 
  2860.              (format "%s %s %s" command path file-name))))
  2861.  
  2862. (defun gnus-uu-post-news-inews ()
  2863.   "Posts the composed news article and encoded file.
  2864. If no file has been included, the user will be asked for a file."
  2865.   (interactive)
  2866.   (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
  2867.       (error "Not in post news buffer"))
  2868.  
  2869.   (let (file-name)
  2870.  
  2871.     (if gnus-uu-post-inserted-file-name
  2872.     (setq file-name gnus-uu-post-inserted-file-name)
  2873.       (setq file-name (gnus-uu-post-insert-binary)))
  2874.   
  2875.     (if gnus-uu-post-threaded
  2876.     (let ((gnus-required-headers 
  2877.            (if (memq 'Message-ID gnus-required-headers)
  2878.            gnus-required-headers
  2879.          (cons 'Message-ID gnus-required-headers)))
  2880.           gnus-inews-article-hook elem)
  2881.  
  2882.       (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook)
  2883.                         gnus-inews-article-hook
  2884.                       (list gnus-inews-article-hook)))
  2885.       (setq gnus-inews-article-hook 
  2886.         (cons
  2887.          '(lambda ()
  2888.             (save-excursion
  2889.               (goto-char 1)
  2890.               (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t)
  2891.               (setq gnus-uu-post-message-id 
  2892.                 (buffer-substring 
  2893.                  (match-beginning 1) (match-end 1)))
  2894.             (setq gnus-uu-post-message-id nil))))
  2895.          gnus-inews-article-hook))
  2896.       (gnus-uu-post-encoded file-name t))
  2897.       (gnus-uu-post-encoded file-name nil)))
  2898.   (setq gnus-uu-post-inserted-file-name nil)
  2899.   (and gnus-uu-winconf-post-news
  2900.        (set-window-configuration gnus-uu-winconf-post-news)))
  2901.       
  2902. ; Asks for a file to encode, encodes it and inserts the result in
  2903. ; the current buffer. Returns the file name the user gave.
  2904. (defun gnus-uu-post-insert-binary ()
  2905.   (let ((uuencode-buffer-name "*uuencode buffer*")
  2906.     file-path post-buf uubuf file-name)
  2907.  
  2908.     (setq file-path (read-file-name 
  2909.              "What file do you want to encode? "))
  2910.     (if (not (file-exists-p file-path))
  2911.     (error "%s: No such file" file-path))
  2912.  
  2913.     (goto-char (point-max))
  2914.     (insert (format "\n%s\n" gnus-uu-post-binary-separator))
  2915.     
  2916.     (if (string-match "^~/" file-path)
  2917.     (setq file-path (concat "$HOME" (substring file-path 1))))
  2918.     (if (string-match "/[^/]*$" file-path)
  2919.     (setq file-name (substring file-path (1+ (match-beginning 0))))
  2920.       (setq file-name file-path))
  2921.  
  2922.     (unwind-protect
  2923.     (if (save-excursion
  2924.           (set-buffer (setq uubuf 
  2925.                 (get-buffer-create uuencode-buffer-name)))
  2926.           (erase-buffer)
  2927.           (funcall gnus-uu-post-encode-method file-path file-name))
  2928.         (insert-buffer uubuf)
  2929.       (error "Encoding unsuccessful"))
  2930.       (kill-buffer uubuf))
  2931.     file-name))
  2932.  
  2933. ; Posts the article and all of the encoded file.
  2934. (defun gnus-uu-post-encoded (file-name &optional threaded)
  2935.   (let ((send-buffer-name "*uuencode send buffer*")
  2936.     (encoded-buffer-name "*encoded buffer*")
  2937.     (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
  2938.     (separator (concat mail-header-separator "\n\n"))
  2939.     file uubuf length parts header i end beg
  2940.     beg-line minlen buf post-buf whole-len beg-binary end-binary)
  2941.  
  2942.     (setq post-buf (current-buffer))
  2943.  
  2944.     (goto-char 1)
  2945.     (if (not (re-search-forward 
  2946.           (if gnus-uu-post-separate-description 
  2947.           gnus-uu-post-binary-separator 
  2948.         mail-header-separator) nil t))
  2949.     (error "Internal error: No binary/header separator"))
  2950.     (beginning-of-line)
  2951.     (forward-line 1)
  2952.     (setq beg-binary (point))
  2953.     (setq end-binary (point-max))
  2954.  
  2955.     (save-excursion 
  2956.       (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name)))
  2957.       (erase-buffer)
  2958.       (insert-buffer-substring post-buf beg-binary end-binary)
  2959.       (goto-char 1)
  2960.       (setq length (count-lines 1 (point-max)))
  2961.       (setq parts (/ length gnus-uu-post-length))
  2962.       (if (not (< (% length gnus-uu-post-length) 4))
  2963.       (setq parts (1+ parts))))
  2964.  
  2965.     (if gnus-uu-post-separate-description
  2966.     (forward-line -1))
  2967.     (kill-region (point) (point-max))
  2968.  
  2969.     (goto-char 1)
  2970.     (search-forward mail-header-separator nil t)
  2971.     (beginning-of-line)
  2972.     (setq header (buffer-substring 1 (point)))
  2973.  
  2974.     (goto-char 1)
  2975.     (if (not gnus-uu-post-separate-description)
  2976.     ()
  2977.       (if (and (not threaded) (re-search-forward "^Subject: " nil t))
  2978.       (progn
  2979.         (end-of-line)
  2980.         (insert (format " (0/%d)" parts))))
  2981.       (gnus-inews-news))
  2982.  
  2983.     (save-excursion
  2984.       (setq i 1)
  2985.       (setq beg 1)
  2986.       (while (not (> i parts))
  2987.     (set-buffer (get-buffer-create send-buffer-name))
  2988.     (erase-buffer)
  2989.     (insert header)
  2990.     (if (and threaded gnus-uu-post-message-id)
  2991.         (insert (format "References: %s\n" gnus-uu-post-message-id)))
  2992.     (insert separator)
  2993.     (setq whole-len
  2994.           (- 62 (length (format top-string "" file-name i parts ""))))
  2995.     (if (> 1 (setq minlen (/ whole-len 2)))
  2996.         (setq minlen 1))
  2997.     (setq 
  2998.      beg-line 
  2999.      (format top-string
  3000.          (make-string minlen ?-) 
  3001.          file-name i parts
  3002.          (make-string 
  3003.           (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
  3004.  
  3005.     (goto-char 1)
  3006.     (if (not (re-search-forward "^Subject: " nil t))
  3007.         ()
  3008.       (if (not threaded)
  3009.           (progn
  3010.         (end-of-line)
  3011.         (insert (format " (%d/%d)" i parts)))
  3012.         (if (or (and (= i 2) gnus-uu-post-separate-description)
  3013.             (and (= i 1) (not gnus-uu-post-separate-description)))
  3014.         (replace-match "Subject: Re: "))))
  3015.           
  3016.     (goto-char (point-max))
  3017.     (save-excursion
  3018.       (set-buffer uubuf)
  3019.       (goto-char beg)
  3020.       (if (= i parts)
  3021.           (goto-char (point-max))
  3022.         (forward-line gnus-uu-post-length))
  3023.       (if (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
  3024.           (forward-line -4))
  3025.       (setq end (point)))
  3026.     (insert-buffer-substring uubuf beg end)
  3027.     (insert beg-line)
  3028.     (insert "\n")
  3029.     (setq beg end)
  3030.     (setq i (1+ i))
  3031.     (goto-char 1)
  3032.     (re-search-forward mail-header-separator nil t)
  3033.     (beginning-of-line)
  3034.     (forward-line 2)
  3035.     (if (re-search-forward gnus-uu-post-binary-separator nil t)
  3036.         (progn 
  3037.           (replace-match "")
  3038.           (forward-line 1)))
  3039.     (insert beg-line)
  3040.     (insert "\n")
  3041.     (gnus-inews-news)))
  3042.  
  3043.     (and (setq buf (get-buffer send-buffer-name))
  3044.      (kill-buffer buf))
  3045.     (and (setq buf (get-buffer encoded-buffer-name))
  3046.      (kill-buffer buf))
  3047.  
  3048.     (if (not gnus-uu-post-separate-description)
  3049.     (progn
  3050.       (set-buffer-modified-p nil)
  3051.       (and (fboundp 'bury-buffer) (bury-buffer))))))
  3052.  
  3053. (provide 'gnus-uu)
  3054.  
  3055. ;; gnus-uu.el ends here
  3056.